]> git.lyx.org Git - lyx.git/blob - src/insets/InsetTabular.h
simplify logic
[lyx.git] / src / insets / InsetTabular.h
1 // -*- C++ -*-
2 /**
3  * \file InsetTabular.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Matthias Ettrich
9  * \author André Pönitz
10  * \author Jürgen Vigna
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15
16 // This is Juergen's rewrite of the tabular (table) support.
17
18 // Things to think of when designing the new tabular support:
19 // - color support (colortbl, color)
20 // - decimal alignment (dcloumn)
21 // - custom lines (hhline)
22 // - rotation
23 // - multicolumn
24 // - multirow
25 // - column styles
26
27 // This is what I have written about tabular support in the LyX3-Tasks file:
28 //
29 //  o rewrite of table code. Should probably be written as some
30 //    kind of an inset. [Done]
31 // o enhance longtable support
32
33 // Lgb
34
35 #ifndef INSETTABULAR_H
36 #define INSETTABULAR_H
37
38 #include "Inset.h"
39 #include "InsetText.h"
40 #include "Layout.h"
41 #include "Length.h"
42 #include "MailInset.h"
43
44 #include <boost/shared_ptr.hpp>
45
46 #include <iosfwd>
47 #include <vector>
48
49 namespace lyx {
50
51 class Buffer;
52 class BufferParams;
53 class BufferView;
54 class CompletionList;
55 class CursorSlice;
56 class InsetTableCell;
57 class FuncStatus;
58 class Lexer;
59 class Paragraph;
60
61 namespace frontend { class Painter; }
62
63
64 class InsetTabular;
65 class Cursor;
66 class OutputParams;
67
68 //
69 // A helper struct for tables
70 //
71 class Tabular {
72 public:
73         ///
74         enum Feature {
75                 ///
76                 APPEND_ROW = 0,
77                 ///
78                 APPEND_COLUMN,
79                 ///
80                 DELETE_ROW,
81                 ///
82                 DELETE_COLUMN,
83                 ///
84                 COPY_ROW,
85                 ///
86                 COPY_COLUMN,
87                 ///
88                 TOGGLE_LINE_TOP,
89                 ///
90                 TOGGLE_LINE_BOTTOM,
91                 ///
92                 TOGGLE_LINE_LEFT,
93                 ///
94                 TOGGLE_LINE_RIGHT,
95                 ///
96                 ALIGN_LEFT,
97                 ///
98                 ALIGN_RIGHT,
99                 ///
100                 ALIGN_CENTER,
101                 ///
102                 ALIGN_BLOCK,
103                 ///
104                 VALIGN_TOP,
105                 ///
106                 VALIGN_BOTTOM,
107                 ///
108                 VALIGN_MIDDLE,
109                 ///
110                 M_ALIGN_LEFT,
111                 ///
112                 M_ALIGN_RIGHT,
113                 ///
114                 M_ALIGN_CENTER,
115                 ///
116                 M_VALIGN_TOP,
117                 ///
118                 M_VALIGN_BOTTOM,
119                 ///
120                 M_VALIGN_MIDDLE,
121                 ///
122                 MULTICOLUMN,
123                 ///
124                 SET_ALL_LINES,
125                 ///
126                 UNSET_ALL_LINES,
127                 ///
128                 SET_LONGTABULAR,
129                 ///
130                 UNSET_LONGTABULAR,
131                 ///
132                 SET_PWIDTH,
133                 ///
134                 SET_MPWIDTH,
135                 ///
136                 SET_ROTATE_TABULAR,
137                 ///
138                 UNSET_ROTATE_TABULAR,
139                 ///
140                 TOGGLE_ROTATE_TABULAR,
141                 ///
142                 SET_ROTATE_CELL,
143                 ///
144                 UNSET_ROTATE_CELL,
145                 ///
146                 TOGGLE_ROTATE_CELL,
147                 ///
148                 SET_USEBOX,
149                 ///
150                 SET_LTHEAD,
151                 UNSET_LTHEAD,
152                 ///
153                 SET_LTFIRSTHEAD,
154                 UNSET_LTFIRSTHEAD,
155                 ///
156                 SET_LTFOOT,
157                 UNSET_LTFOOT,
158                 ///
159                 SET_LTLASTFOOT,
160                 UNSET_LTLASTFOOT,
161                 ///
162                 SET_LTNEWPAGE,
163                 ///
164                 SET_SPECIAL_COLUMN,
165                 ///
166                 SET_SPECIAL_MULTI,
167                 ///
168                 SET_BOOKTABS,
169                 ///
170                 UNSET_BOOKTABS,
171                 ///
172                 SET_TOP_SPACE,
173                 ///
174                 SET_BOTTOM_SPACE,
175                 ///
176                 SET_INTERLINE_SPACE,
177                 ///
178                 SET_BORDER_LINES,
179                 ///
180                 LAST_ACTION
181         };
182         ///
183         enum {
184                 ///
185                 CELL_NORMAL = 0,
186                 ///
187                 CELL_BEGIN_OF_MULTICOLUMN,
188                 ///
189                 CELL_PART_OF_MULTICOLUMN
190         };
191
192         ///
193         enum VAlignment {
194                 ///
195                 LYX_VALIGN_TOP = 0,
196                 ///
197                 LYX_VALIGN_BOTTOM = 1,
198                 ///
199                 LYX_VALIGN_MIDDLE = 2
200         };
201
202         enum BoxType {
203                 ///
204                 BOX_NONE = 0,
205                 ///
206                 BOX_PARBOX = 1,
207                 ///
208                 BOX_MINIPAGE = 2
209         };
210
211         class ltType {
212         public:
213                 // constructor
214                 ltType();
215                 // we have this header type (is set in the getLT... functions)
216                 bool set;
217                 // double borders on top
218                 bool topDL;
219                 // double borders on bottom
220                 bool bottomDL;
221                 // used for FirstHeader & LastFooter and if this is true
222                 // all the rows marked as FirstHeader or LastFooter are
223                 // ignored in the output and it is set to be empty!
224                 bool empty;
225         };
226
227         /// type for row numbers
228         typedef size_t row_type;
229         /// type for column numbers
230         typedef size_t col_type;
231         /// type for cell indices
232         typedef size_t idx_type;
233         /// index indicating an invalid position
234         static const idx_type npos = static_cast<idx_type>(-1);
235
236         /// constructor
237         Tabular();
238         /// constructor
239         Tabular(Buffer const &, col_type columns_arg, row_type rows_arg);
240
241         /// Returns true if there is a topline, returns false if not
242         bool topLine(idx_type cell) const;
243         /// Returns true if there is a topline, returns false if not
244         bool bottomLine(idx_type cell) const;
245         /// Returns true if there is a topline, returns false if not
246         bool leftLine(idx_type cell) const;
247         /// Returns true if there is a topline, returns false if not
248         bool rightLine(idx_type cell) const;
249
250         ///
251         bool topAlreadyDrawn(idx_type cell) const;
252         ///
253         bool leftAlreadyDrawn(idx_type cell) const;
254         ///
255         bool isLastRow(idx_type cell) const;
256
257         /// return space occupied by the second horizontal line and
258         /// interline space above row \p row in pixels
259         int getAdditionalHeight(row_type row) const;
260         ///
261         int getAdditionalWidth(idx_type cell) const;
262
263         /* returns the maximum over all rows */
264         ///
265         int columnWidth(idx_type cell) const;
266         ///
267         int width() const;
268         ///
269         int height() const;
270         ///
271         int rowAscent(row_type row) const;
272         ///
273         int rowDescent(row_type row) const;
274         ///
275         void setRowAscent(row_type row, int height);
276         ///
277         void setRowDescent(row_type row, int height);
278         ///
279         void setCellWidth(idx_type cell, int new_width);
280         ///
281         void setAllLines(idx_type cell, bool line);
282         ///
283         void setTopLine(idx_type cell, bool line);
284         ///
285         void setBottomLine(idx_type cell, bool line);
286         ///
287         void setLeftLine(idx_type cell, bool line);
288         ///
289         void setRightLine(idx_type cell, bool line);
290         ///
291         bool rowTopLine(row_type row) const;
292         ///
293         bool rowBottomLine(row_type row) const;
294         ///
295         bool columnLeftLine(col_type column) const;
296         ///
297         bool columnRightLine(col_type column) const;
298
299         void setAlignment(idx_type cell, LyXAlignment align,
300                           bool onlycolumn = false);
301         ///
302         void setVAlignment(idx_type cell, VAlignment align,
303                            bool onlycolumn = false);
304         ///
305         void setColumnPWidth(Cursor &, idx_type, Length const &);
306         ///
307         bool setMColumnPWidth(Cursor &, idx_type, Length const &);
308         ///
309         void setAlignSpecial(idx_type cell, docstring const & special,
310                              Feature what);
311         ///
312         LyXAlignment getAlignment(idx_type cell,
313                                   bool onlycolumn = false) const;
314         ///
315         VAlignment getVAlignment(idx_type cell,
316                                  bool onlycolumn = false) const;
317         ///
318         Length const getPWidth(idx_type cell) const;
319         ///
320         Length const getColumnPWidth(idx_type cell) const;
321         ///
322         Length const getMColumnPWidth(idx_type cell) const;
323         ///
324         docstring const getAlignSpecial(idx_type cell, int what) const;
325         ///
326         int cellWidth(idx_type cell) const;
327         ///
328         int getBeginningOfTextInCell(idx_type cell) const;
329         ///
330         void appendRow(idx_type cell);
331         ///
332         void deleteRow(row_type row);
333         ///
334         void copyRow(row_type);
335         ///
336         void appendColumn(idx_type cell);
337         ///
338         void deleteColumn(col_type column);
339         ///
340         void copyColumn(col_type);
341         ///
342         bool isFirstCellInRow(idx_type cell) const;
343         ///
344         idx_type getFirstCellInRow(row_type row) const;
345         ///
346         bool isLastCellInRow(idx_type cell) const;
347         ///
348         idx_type getLastCellInRow(row_type row) const;
349         ///
350         idx_type cellCount() const;
351         ///
352         idx_type numberOfCellsInRow(idx_type cell) const;
353         ///
354         void write(std::ostream &) const;
355         ///
356         void read(Lexer &);
357         ///
358         int latex(odocstream &, OutputParams const &) const;
359         //
360         int docbook(odocstream & os, OutputParams const &) const;
361         ///
362         void plaintext(odocstream &,
363                        OutputParams const & runparams, int const depth,
364                        bool onlydata, char_type delim) const;
365         ///
366         bool isMultiColumn(idx_type cell) const;
367         ///
368         bool isMultiColumnReal(idx_type cell) const;
369         ///
370         void setMultiColumn(idx_type cell, idx_type number);
371         ///
372         idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
373         ///
374         bool isPartOfMultiColumn(row_type row, col_type column) const;
375         ///
376         row_type cellRow(idx_type cell) const;
377         ///
378         col_type cellColumn(idx_type cell) const;
379         ///
380         col_type cellRightColumn(idx_type cell) const;
381         ///
382         void setBookTabs(bool);
383         ///
384         bool useBookTabs() const;
385         ///
386         void setLongTabular(bool);
387         ///
388         bool isLongTabular() const;
389         ///
390         void setRotateTabular(bool);
391         ///
392         bool getRotateTabular() const;
393         ///
394         void setRotateCell(idx_type cell, bool);
395         ///
396         bool getRotateCell(idx_type cell) const;
397         ///
398         bool needRotating() const;
399         ///
400         bool isLastCell(idx_type cell) const;
401         ///
402         idx_type getCellAbove(idx_type cell) const;
403         ///
404         idx_type getCellBelow(idx_type cell) const;
405         ///
406         idx_type cellIndex(row_type row, col_type column) const;
407         ///
408         void setUsebox(idx_type cell, BoxType);
409         ///
410         BoxType getUsebox(idx_type cell) const;
411         //
412         // Long Tabular Options support functions
413         ///
414         bool checkLTType(row_type row, ltType const &) const;
415         ///
416         void setLTHead(row_type row, bool flag, ltType const &, bool first);
417         ///
418         bool getRowOfLTHead(row_type row, ltType &) const;
419         ///
420         bool getRowOfLTFirstHead(row_type row, ltType &) const;
421         ///
422         void setLTFoot(row_type row, bool flag, ltType const &, bool last);
423         ///
424         bool getRowOfLTFoot(row_type row, ltType &) const;
425         ///
426         bool getRowOfLTLastFoot(row_type row, ltType &) const;
427         ///
428         void setLTNewPage(row_type row, bool what);
429         ///
430         bool getLTNewPage(row_type row) const;
431         ///
432         bool haveLTHead() const;
433         ///
434         bool haveLTFirstHead() const;
435         ///
436         bool haveLTFoot() const;
437         ///
438         bool haveLTLastFoot() const;
439         ///
440         // end longtable support
441         ///
442         boost::shared_ptr<InsetTableCell> getCellInset(idx_type cell) const;
443         ///
444         boost::shared_ptr<InsetTableCell> getCellInset(row_type row,
445                                                   col_type column) const;
446         ///
447         void setCellInset(row_type row, col_type column,
448                           boost::shared_ptr<InsetTableCell>) const;
449         /// Search for \param inset in the tabular, with the
450         ///
451         idx_type getCellFromInset(Inset const * inset) const;
452         ///
453         row_type rowCount() const { return row_info.size(); }
454         ///
455         col_type columnCount() const { return column_info.size();}
456         ///
457         void validate(LaTeXFeatures &) const;
458         ///
459 //private:
460         ///
461         class CellData {
462         public:
463                 ///
464                 CellData(Buffer const &, Tabular const &);
465                 ///
466                 CellData(CellData const &);
467                 ///
468                 CellData & operator=(CellData);
469                 ///
470                 void swap(CellData & rhs);
471                 ///
472                 idx_type cellno;
473                 ///
474                 int width;
475                 ///
476                 int multicolumn;
477                 ///
478                 LyXAlignment alignment;
479                 ///
480                 VAlignment valignment;
481                 ///
482                 bool top_line;
483                 ///
484                 bool bottom_line;
485                 ///
486                 bool left_line;
487                 ///
488                 bool right_line;
489                 ///
490                 BoxType usebox;
491                 ///
492                 bool rotate;
493                 ///
494                 docstring align_special;
495                 ///
496                 Length p_width; // this is only set for multicolumn!!!
497                 ///
498                 boost::shared_ptr<InsetTableCell> inset;
499         };
500         CellData & cellinfo_of_cell(idx_type cell) const;
501         ///
502         typedef std::vector<CellData> cell_vector;
503         ///
504         typedef std::vector<cell_vector> cell_vvector;
505
506         ///
507         class RowData {
508         public:
509                 ///
510                 RowData();
511                 ///
512                 int ascent;
513                 ///
514                 int descent;
515                 ///
516                 bool top_line;
517                 ///
518                 bool bottom_line;
519                 /// Extra space between the top line and this row
520                 Length top_space;
521                 /// Ignore top_space if true and use the default top space
522                 bool top_space_default;
523                 /// Extra space between this row and the bottom line
524                 Length bottom_space;
525                 /// Ignore bottom_space if true and use the default bottom space
526                 bool bottom_space_default;
527                 /// Extra space between the bottom line and the next top line
528                 Length interline_space;
529                 /// Ignore interline_space if true and use the default interline space
530                 bool interline_space_default;
531                 /// This are for longtabulars only
532                 /// a row of endhead
533                 bool endhead;
534                 /// a row of endfirsthead
535                 bool endfirsthead;
536                 /// a row of endfoot
537                 bool endfoot;
538                 /// row of endlastfoot
539                 bool endlastfoot;
540                 /// row for a newpage
541                 bool newpage;
542         };
543         ///
544         typedef std::vector<RowData> row_vector;
545
546         ///
547         class ColumnData {
548                 public:
549                 ///
550                 ColumnData();
551                 ///
552                 LyXAlignment alignment;
553                 ///
554                 VAlignment valignment;
555                 ///
556                 bool left_line;
557                 ///
558                 bool right_line;
559                 ///
560                 int width;
561                 ///
562                 Length p_width;
563                 ///
564                 docstring align_special;
565         };
566         ///
567         typedef std::vector<ColumnData> column_vector;
568
569         ///
570         idx_type numberofcells;
571         ///
572         std::vector<row_type> rowofcell;
573         ///
574         std::vector<col_type> columnofcell;
575         ///
576         row_vector row_info;
577         ///
578         column_vector column_info;
579         ///
580         mutable cell_vvector cell_info;
581         ///
582         bool use_booktabs;
583         ///
584         bool rotate;
585         //
586         // for long tabulars
587         //
588         bool is_long_tabular;
589         /// endhead data
590         ltType endhead;
591         /// endfirsthead data
592         ltType endfirsthead;
593         /// endfoot data
594         ltType endfoot;
595         /// endlastfoot data
596         ltType endlastfoot;
597
598         ///
599         void init(Buffer const &, row_type rows_arg,
600                   col_type columns_arg);
601         ///
602         void updateIndexes();
603         /// Returns true if a complete update is necessary, otherwise false
604         bool setWidthOfMulticolCell(idx_type cell, int new_width);
605         ///
606         void recalculateMulticolumnsOfColumn(col_type column);
607         /// Returns true if change
608         void calculate_width_of_column(col_type column);
609         ///
610         bool calculate_width_of_column_NMC(col_type column); // no multi cells
611         ///
612         idx_type columnSpan(idx_type cell) const;
613         ///
614         BoxType useParbox(idx_type cell) const;
615         ///
616         // helper function for Latex returns number of newlines
617         ///
618         int TeXTopHLine(odocstream &, row_type row) const;
619         ///
620         int TeXBottomHLine(odocstream &, row_type row) const;
621         ///
622         int TeXCellPreamble(odocstream &, idx_type cell) const;
623         ///
624         int TeXCellPostamble(odocstream &, idx_type cell) const;
625         ///
626         int TeXLongtableHeaderFooter(odocstream &, OutputParams const &) const;
627         ///
628         bool isValidRow(row_type const row) const;
629         ///
630         int TeXRow(odocstream &, row_type const row,
631                    OutputParams const &) const;
632         ///
633         // helper functions for plain text
634         ///
635         bool plaintextTopHLine(odocstream &, row_type row,
636                                std::vector<unsigned int> const &) const;
637         ///
638         bool plaintextBottomHLine(odocstream &, row_type row,
639                                   std::vector<unsigned int> const &) const;
640         ///
641         void plaintextPrintCell(odocstream &,
642                                 OutputParams const &,
643                                 idx_type cell, row_type row, col_type column,
644                                 std::vector<unsigned int> const &,
645                                 bool onlydata) const;
646         /// auxiliary function for docbook
647         int docbookRow(odocstream & os, row_type, OutputParams const &) const;
648
649         /// change associated Buffer
650         void setBuffer(Buffer const & buffer) { buffer_ = &buffer; }
651         /// retrieve associated Buffer
652         Buffer const & buffer() const { return *buffer_; }
653
654 private:
655         Buffer const * buffer_;
656
657 }; // Tabular
658
659
660 ///
661 class InsetTableCell : public InsetText {
662 public:
663         ///
664         explicit InsetTableCell(Buffer const & buf,
665                 Tabular::CellData const * cd, Tabular const * t);
666         ///
667         virtual InsetCode lyxCode() const { return CELL_CODE; }
668         ///
669         Inset * clone() { return new InsetTableCell(*this); }
670         ///
671         virtual bool useEmptyLayout() const { return true; }
672         /// 
673         virtual bool forceEmptyLayout(idx_type = 0) const;
674         /// 
675         virtual bool allowParagraphCustomization(idx_type = 0) const;
676         ///
677         bool getStatus(Cursor & cur, FuncRequest const & cmd,
678                 FuncStatus & status) const;
679         ///
680         virtual bool neverIndent() { return true; }
681         ///
682         void setCellData(Tabular::CellData const * cd) { cell_data_ = cd; }
683         ///
684         void setTabular(Tabular const * t) { table_ = t; }
685 private:
686         /// 
687         Tabular::CellData const * cell_data_;
688         /// 
689         Tabular const * table_;
690         /// unimplemented
691         InsetTableCell();
692         /// unimplemented
693         void operator=(InsetTableCell const &);
694 };
695
696
697 class InsetTabular : public Inset {
698 public:
699         ///
700         InsetTabular(Buffer const &, row_type rows = 1,
701                      col_type columns = 1);
702         ///
703         ~InsetTabular();
704         ///
705         void read(Lexer &);
706         ///
707         void write(std::ostream &) const;
708         ///
709         void metrics(MetricsInfo &, Dimension &) const;
710         ///
711         void draw(PainterInfo & pi, int x, int y) const;
712         ///
713         void drawSelection(PainterInfo & pi, int x, int y) const;
714         ///
715         docstring editMessage() const;
716         ///
717         EDITABLE editable() const { return HIGHLY_EDITABLE; }
718         ///
719         bool insetAllowed(InsetCode code) const;
720         ///
721         bool allowSpellCheck() const { return true; }
722         ///
723         bool canTrackChanges() const { return true; }
724         /** returns true if, when outputing LaTeX, font changes should
725             be closed before generating this inset. This is needed for
726             insets that may contain several paragraphs */
727         bool noFontChange() const { return true; }
728         ///
729         DisplayType display() const { return tabular.isLongTabular() ? AlignCenter : Inline; }
730         ///
731         int latex(odocstream &, OutputParams const &) const;
732         ///
733         int plaintext(odocstream &, OutputParams const &) const;
734         ///
735         int docbook(odocstream &, OutputParams const &) const;
736         ///
737         void validate(LaTeXFeatures & features) const;
738         ///
739         InsetCode lyxCode() const { return TABULAR_CODE; }
740         /// get offset of this cursor slice relative to our upper left corner
741         void cursorPos(BufferView const & bv, CursorSlice const & sl,
742                 bool boundary, int & x, int & y) const;
743         ///
744         bool tabularFeatures(Cursor & cur, std::string const & what);
745         ///
746         void tabularFeatures(Cursor & cur, Tabular::Feature feature,
747                              std::string const & val = std::string());
748         ///
749         void openLayoutDialog(BufferView *) const;
750         ///
751         bool showInsetDialog(BufferView *) const;
752         /// number of cells
753         size_t nargs() const { return tabular.cellCount(); }
754         ///
755         boost::shared_ptr<InsetTableCell const> cell(idx_type) const;
756         ///
757         boost::shared_ptr<InsetTableCell> cell(idx_type);
758         ///
759         Text * getText(int) const;
760
761         /// set the change for the entire inset
762         void setChange(Change const & change);
763         /// accept the changes within the inset
764         void acceptChanges(BufferParams const & bparams);
765         /// reject the changes within the inset
766         void rejectChanges(BufferParams const & bparams);
767
768         // this should return true if we have a "normal" cell, otherwise false.
769         // "normal" means without width set!
770         /// should all paragraphs be output with "Standard" layout?
771         virtual bool allowParagraphCustomization(idx_type cell = 0) const;
772         ///
773         virtual bool forceEmptyLayout(idx_type cell = 0) const;
774         ///
775         virtual bool useEmptyLayout() { return true; }
776         ///
777         void addPreview(graphics::PreviewLoader &) const;
778
779         /// lock cell with given index
780         void edit(Cursor & cur, bool front, EntryDirection entry_from);
781         /// get table row from x coordinate
782         int rowFromY(Cursor & cur, int y) const;
783         /// get table column from y coordinate
784         int columnFromX(Cursor & cur, int x) const;
785         ///
786         Inset * editXY(Cursor & cur, int x, int y);
787         /// can we go further down on mouse click?
788         bool descendable() const { return true; }
789         // Update the counters of this inset and of its contents
790         void updateLabels(ParIterator const &);
791
792         ///
793         bool completionSupported(Cursor const &) const;
794         ///
795         bool inlineCompletionSupported(Cursor const & cur) const;
796         ///
797         bool automaticInlineCompletion() const;
798         ///
799         bool automaticPopupCompletion() const;
800         ///
801         bool showCompletionCursor() const;
802         ///
803         CompletionList const * createCompletionList(Cursor const & cur) const;
804         ///
805         docstring completionPrefix(Cursor const & cur) const;
806         ///
807         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
808         ///
809         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
810
811         //
812         // Public structures and variables
813         ///
814         mutable Tabular tabular;
815
816 private:
817         ///
818         InsetTabular(InsetTabular const &);
819         ///
820         void doDispatch(Cursor & cur, FuncRequest & cmd);
821         ///
822         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
823         ///
824         int scroll() const { return scx_; }
825         ///
826         Inset * clone() const { return new InsetTabular(*this); }
827
828         ///
829         void drawCellLines(frontend::Painter &, int x, int y, row_type row,
830                            idx_type cell, bool erased) const;
831         ///
832         void setCursorFromCoordinates(Cursor & cur, int x, int y) const;
833
834         ///
835         void moveNextCell(Cursor & cur);
836         ///
837         void movePrevCell(Cursor & cur);
838         ///
839         int getCellXPos(idx_type cell) const;
840         ///
841         void resetPos(Cursor & cur) const;
842         ///
843         void removeTabularRow();
844         ///
845         bool copySelection(Cursor & cur);
846         ///
847         bool pasteClipboard(Cursor & cur);
848         ///
849         void cutSelection(Cursor & cur);
850         ///
851         bool isRightToLeft(Cursor & cur) const;
852         ///
853         void getSelection(Cursor & cur, row_type & rs, row_type & re,
854                           col_type & cs, col_type & ce) const;
855         ///
856         bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
857         /// are we operating on several cells?
858         bool tablemode(Cursor & cur) const;
859
860         /// return the "Manhattan distance" to nearest corner
861         int dist(BufferView &, idx_type cell, int x, int y) const;
862         /// return the cell nearest to x, y
863         idx_type getNearestCell(BufferView &, int x, int y) const;
864
865         /// test the rotation state of the give cell range.
866         bool oneCellHasRotationState(bool rotated,
867                                 row_type row_start, row_type row_end,
868                                 col_type col_start, col_type col_end) const;
869         ///
870         mutable idx_type first_visible_cell;
871         ///
872         mutable int scx_;
873 };
874
875
876 class InsetTabularMailer : public MailInset {
877 public:
878         ///
879         InsetTabularMailer(InsetTabular const & inset);
880         ///
881         virtual Inset & inset() const { return inset_; }
882         ///
883         virtual std::string const & name() const { return name_; }
884         ///
885         virtual std::string const inset2string(Buffer const &) const;
886         ///
887         static void string2params(std::string const &, InsetTabular &);
888         ///
889         static std::string const params2string(InsetTabular const &);
890 private:
891         ///
892         static std::string const name_;
893         ///
894         InsetTabular & inset_;
895 };
896
897 std::string const featureAsString(Tabular::Feature feature);
898
899 } // namespace lyx
900
901 #endif