]> git.lyx.org Git - lyx.git/blob - src/insets/InsetTabular.h
un-revert r30531, after Richard told me how to avoid the crash. Now, before
[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 INSET_TABULAR_H
36 #define INSET_TABULAR_H
37
38 #include "Inset.h"
39 #include "InsetText.h"
40 #include "Layout.h"
41 #include "Length.h"
42
43 #include <boost/shared_ptr.hpp>
44
45 #include <iosfwd>
46 #include <vector>
47
48 namespace lyx {
49
50 class Buffer;
51 class BufferView;
52 class CompletionList;
53 class CursorSlice;
54 class InsetTableCell;
55 class FuncStatus;
56 class Lexer;
57 class Paragraph;
58
59 namespace frontend { class Painter; }
60
61
62 class InsetTabular;
63 class Cursor;
64 class OutputParams;
65
66 //
67 // A helper struct for tables
68 //
69 class Tabular {
70 public:
71         ///
72         enum Feature {
73                 ///
74                 APPEND_ROW = 0,
75                 ///
76                 APPEND_COLUMN,
77                 ///
78                 DELETE_ROW,
79                 ///
80                 DELETE_COLUMN,
81                 ///
82                 COPY_ROW,
83                 ///
84                 COPY_COLUMN,
85                 ///
86                 TOGGLE_LINE_TOP,
87                 ///
88                 TOGGLE_LINE_BOTTOM,
89                 ///
90                 TOGGLE_LINE_LEFT,
91                 ///
92                 TOGGLE_LINE_RIGHT,
93                 ///
94                 ALIGN_LEFT,
95                 ///
96                 ALIGN_RIGHT,
97                 ///
98                 ALIGN_CENTER,
99                 ///
100                 ALIGN_BLOCK,
101                 ///
102                 VALIGN_TOP,
103                 ///
104                 VALIGN_BOTTOM,
105                 ///
106                 VALIGN_MIDDLE,
107                 ///
108                 M_ALIGN_LEFT,
109                 ///
110                 M_ALIGN_RIGHT,
111                 ///
112                 M_ALIGN_CENTER,
113                 ///
114                 M_VALIGN_TOP,
115                 ///
116                 M_VALIGN_BOTTOM,
117                 ///
118                 M_VALIGN_MIDDLE,
119                 ///
120                 MULTICOLUMN,
121                 ///
122                 SET_ALL_LINES,
123                 ///
124                 UNSET_ALL_LINES,
125                 ///
126                 SET_LONGTABULAR,
127                 ///
128                 UNSET_LONGTABULAR,
129                 ///
130                 SET_PWIDTH,
131                 ///
132                 SET_MPWIDTH,
133                 ///
134                 SET_ROTATE_TABULAR,
135                 ///
136                 UNSET_ROTATE_TABULAR,
137                 ///
138                 TOGGLE_ROTATE_TABULAR,
139                 ///
140                 SET_ROTATE_CELL,
141                 ///
142                 UNSET_ROTATE_CELL,
143                 ///
144                 TOGGLE_ROTATE_CELL,
145                 ///
146                 SET_USEBOX,
147                 ///
148                 SET_LTHEAD,
149                 UNSET_LTHEAD,
150                 ///
151                 SET_LTFIRSTHEAD,
152                 UNSET_LTFIRSTHEAD,
153                 ///
154                 SET_LTFOOT,
155                 UNSET_LTFOOT,
156                 ///
157                 SET_LTLASTFOOT,
158                 UNSET_LTLASTFOOT,
159                 ///
160                 SET_LTNEWPAGE,
161                 ///
162                 TOGGLE_LTCAPTION,
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                 TABULAR_VALIGN_TOP,
181                 ///
182                 TABULAR_VALIGN_MIDDLE,
183                 ///
184                 TABULAR_VALIGN_BOTTOM,
185                 ///
186                 LONGTABULAR_ALIGN_LEFT,
187                 ///
188                 LONGTABULAR_ALIGN_CENTER,
189                 ///
190                 LONGTABULAR_ALIGN_RIGHT,
191                 ///
192                 LAST_ACTION
193         };
194         ///
195         enum {
196                 ///
197                 CELL_NORMAL = 0,
198                 ///
199                 CELL_BEGIN_OF_MULTICOLUMN,
200                 ///
201                 CELL_PART_OF_MULTICOLUMN
202         };
203
204         ///
205         enum VAlignment {
206                 ///
207                 LYX_VALIGN_TOP = 0,
208                 ///
209                 LYX_VALIGN_MIDDLE = 1,
210                 ///
211                 LYX_VALIGN_BOTTOM = 2
212                 
213         };
214         ///
215         enum HAlignment {
216                 ///
217                 LYX_LONGTABULAR_ALIGN_LEFT = 0,
218                 ///
219                 LYX_LONGTABULAR_ALIGN_CENTER = 1,
220                 ///
221                 LYX_LONGTABULAR_ALIGN_RIGHT = 2
222         };
223
224         enum BoxType {
225                 ///
226                 BOX_NONE = 0,
227                 ///
228                 BOX_PARBOX = 1,
229                 ///
230                 BOX_MINIPAGE = 2
231         };
232
233         class ltType {
234         public:
235                 // constructor
236                 ltType();
237                 // we have this header type (is set in the getLT... functions)
238                 bool set;
239                 // double borders on top
240                 bool topDL;
241                 // double borders on bottom
242                 bool bottomDL;
243                 // used for FirstHeader & LastFooter and if this is true
244                 // all the rows marked as FirstHeader or LastFooter are
245                 // ignored in the output and it is set to be empty!
246                 bool empty;
247         };
248
249         /// type for row numbers
250         typedef size_t row_type;
251         /// type for column numbers
252         typedef size_t col_type;
253         /// type for cell indices
254         typedef size_t idx_type;
255         /// index indicating an invalid position
256         static const idx_type npos = static_cast<idx_type>(-1);
257
258         /// constructor
259         Tabular(Buffer &, col_type columns_arg, row_type rows_arg);
260
261         /// Returns true if there is a topline, returns false if not
262         bool topLine(idx_type cell) const;
263         /// Returns true if there is a topline, returns false if not
264         bool bottomLine(idx_type cell) const;
265         /// Returns true if there is a topline, returns false if not
266         bool leftLine(idx_type cell) const;
267         /// Returns true if there is a topline, returns false if not
268         bool rightLine(idx_type cell) const;
269
270         ///
271         bool topAlreadyDrawn(idx_type cell) const;
272         ///
273         bool leftAlreadyDrawn(idx_type cell) const;
274         ///
275         bool isLastRow(idx_type cell) const;
276
277         /// return space occupied by the second horizontal line and
278         /// interline space above row \p row in pixels
279         int getAdditionalHeight(row_type row) const;
280         ///
281         int getAdditionalWidth(idx_type cell) const;
282
283         /* returns the maximum over all rows */
284         ///
285         int columnWidth(idx_type cell) const;
286         ///
287         int width() const;
288         ///
289         int height() const;
290         ///
291         int rowAscent(row_type row) const;
292         ///
293         int rowDescent(row_type row) const;
294         ///
295         void setRowAscent(row_type row, int height);
296         ///
297         void setRowDescent(row_type row, int height);
298         ///
299         void setCellWidth(idx_type cell, int new_width);
300         ///
301         void setAllLines(idx_type cell, bool line);
302         ///
303         void setTopLine(idx_type cell, bool line);
304         ///
305         void setBottomLine(idx_type cell, bool line);
306         ///
307         void setLeftLine(idx_type cell, bool line);
308         ///
309         void setRightLine(idx_type cell, bool line);
310         ///
311         bool rowTopLine(row_type row) const;
312         ///
313         bool rowBottomLine(row_type row) const;
314         ///
315         bool columnLeftLine(col_type column) const;
316         ///
317         bool columnRightLine(col_type column) const;
318
319         void setAlignment(idx_type cell, LyXAlignment align,
320                           bool onlycolumn = false);
321         ///
322         void setVAlignment(idx_type cell, VAlignment align,
323                            bool onlycolumn = false);
324         ///
325         void setColumnPWidth(Cursor &, idx_type, Length const &);
326         ///
327         bool setMColumnPWidth(Cursor &, idx_type, Length const &);
328         ///
329         void setAlignSpecial(idx_type cell, docstring const & special,
330                              Feature what);
331         ///
332         LyXAlignment getAlignment(idx_type cell,
333                                   bool onlycolumn = false) const;
334         ///
335         VAlignment getVAlignment(idx_type cell,
336                                  bool onlycolumn = false) const;
337         ///
338         Length const getPWidth(idx_type cell) const;
339         ///
340         int cellWidth(idx_type cell) const;
341         ///
342         int getBeginningOfTextInCell(idx_type cell) const;
343         ///
344         void appendRow(idx_type cell);
345         ///
346         void deleteRow(row_type row);
347         ///
348         void copyRow(row_type);
349         ///
350         void appendColumn(idx_type cell);
351         ///
352         void deleteColumn(col_type column);
353         ///
354         void copyColumn(col_type);
355         ///
356         bool isFirstCellInRow(idx_type cell) const;
357         ///
358         idx_type getFirstCellInRow(row_type row) const;
359         ///
360         bool isLastCellInRow(idx_type cell) const;
361         ///
362         idx_type getLastCellInRow(row_type row) const;
363         ///
364         idx_type numberOfCellsInRow(idx_type cell) const;
365         ///
366         void write(std::ostream &) const;
367         ///
368         void read(Lexer &);
369         ///
370         int latex(odocstream &, OutputParams const &) const;
371         //
372         int docbook(odocstream & os, OutputParams const &) const;
373         ///
374         void plaintext(odocstream &,
375                        OutputParams const & runparams, int const depth,
376                        bool onlydata, char_type delim) const;
377         ///
378         bool isMultiColumn(idx_type cell) const;
379         ///
380         bool isMultiColumnReal(idx_type cell) const;
381         ///
382         void setMultiColumn(idx_type cell, idx_type number);
383         ///
384         idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
385         ///
386         bool isPartOfMultiColumn(row_type row, col_type column) const;
387         ///
388         row_type cellRow(idx_type cell) const;
389         ///
390         col_type cellColumn(idx_type cell) const;
391         ///
392         col_type cellRightColumn(idx_type cell) 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 cellAbove(idx_type cell) const;
403         ///
404         idx_type cellBelow(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         idx_type setLTCaption(row_type row, bool what);
433         ///
434         bool ltCaption(row_type row) const;
435         ///
436         bool haveLTHead() const;
437         ///
438         bool haveLTFirstHead() const;
439         ///
440         bool haveLTFoot() const;
441         ///
442         bool haveLTLastFoot() const;
443         ///
444         bool haveLTCaption() const;
445         ///
446         // end longtable support
447         ///
448         boost::shared_ptr<InsetTableCell> cellInset(idx_type cell) const;
449         ///
450         boost::shared_ptr<InsetTableCell> cellInset(row_type row,
451                                                   col_type column) const;
452         ///
453         void setCellInset(row_type row, col_type column,
454                           boost::shared_ptr<InsetTableCell>) const;
455         /// Search for \param inset in the tabular, with the
456         ///
457         void validate(LaTeXFeatures &) const;
458 //private:
459   // FIXME Now that cells have an InsetTableCell as their insets, rather
460   // than an InsetText, it'd be possible to reverse the relationship here,
461   // so that cell_vector was a vector<InsetTableCell> rather than a 
462   // vector<CellData>, and an InsetTableCell had a CellData as a member,
463   // or perhaps just had its members as members.
464         ///
465         class CellData {
466         public:
467                 ///
468                 CellData(Buffer &);
469                 ///
470                 CellData(CellData const &);
471                 ///
472                 CellData & operator=(CellData);
473                 ///
474                 void swap(CellData & rhs);
475                 ///
476                 idx_type cellno;
477                 ///
478                 int width;
479                 ///
480                 int multicolumn;
481                 ///
482                 LyXAlignment alignment;
483                 ///
484                 VAlignment valignment;
485                 ///
486                 bool top_line;
487                 ///
488                 bool bottom_line;
489                 ///
490                 bool left_line;
491                 ///
492                 bool right_line;
493                 ///
494                 BoxType usebox;
495                 ///
496                 bool rotate;
497                 ///
498                 docstring align_special;
499                 ///
500                 Length p_width; // this is only set for multicolumn!!!
501                 ///
502                 boost::shared_ptr<InsetTableCell> inset;
503         };
504         CellData & cellInfo(idx_type cell) const;
505         ///
506         typedef std::vector<CellData> cell_vector;
507         ///
508         typedef std::vector<cell_vector> cell_vvector;
509
510         ///
511         class RowData {
512         public:
513                 ///
514                 RowData();
515                 ///
516                 int ascent;
517                 ///
518                 int descent;
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                 /// caption
543                 bool caption;
544         };
545         ///
546         typedef std::vector<RowData> row_vector;
547
548         ///
549         class ColumnData {
550                 public:
551                 ///
552                 ColumnData();
553                 ///
554                 LyXAlignment alignment;
555                 ///
556                 VAlignment valignment;
557                 ///
558                 int width;
559                 ///
560                 Length p_width;
561                 ///
562                 docstring align_special;
563         };
564         ///
565         typedef std::vector<ColumnData> column_vector;
566
567         ///
568         idx_type numberofcells;
569         ///
570         std::vector<row_type> rowofcell;
571         ///
572         std::vector<col_type> columnofcell;
573         ///
574         row_vector row_info;
575         ///
576         column_vector column_info;
577         ///
578         mutable cell_vvector cell_info;
579         ///
580         bool use_booktabs;
581         ///
582         bool rotate;
583         ///
584         VAlignment tabular_valignment;
585         //
586         // for long tabulars
587         ///
588         HAlignment longtabular_alignment;
589         //
590         bool is_long_tabular;
591         /// endhead data
592         ltType endhead;
593         /// endfirsthead data
594         ltType endfirsthead;
595         /// endfoot data
596         ltType endfoot;
597         /// endlastfoot data
598         ltType endlastfoot;
599
600         ///
601         void init(Buffer &, row_type rows_arg,
602                   col_type columns_arg);
603         ///
604         void updateIndexes();
605         ///
606         bool setFixedWidth(row_type r, col_type c);
607         ///
608         void updateContentAlignment(row_type r, col_type c);
609         /// return true of update is needed
610         bool updateColumnWidths();
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, std::string const lang) const;
619         ///
620         int TeXBottomHLine(odocstream &, row_type row, std::string const lang) const;
621         ///
622         int TeXCellPreamble(odocstream &, idx_type cell, bool & ismulticol) const;
623         ///
624         int TeXCellPostamble(odocstream &, idx_type cell, bool ismulticol) 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 & buffer);
651         /// retrieve associated Buffer
652         Buffer & buffer() const { return *buffer_; }
653
654 private:
655         Buffer * buffer_;
656
657 }; // Tabular
658
659
660 ///
661 class InsetTableCell : public InsetText
662 {
663 public:
664         ///
665         InsetTableCell(Buffer & buf);
666         ///
667         InsetCode lyxCode() const { return CELL_CODE; }
668         ///
669         Inset * clone() { return new InsetTableCell(*this); }
670         ///
671         bool getStatus(Cursor & cur, FuncRequest const & cmd,
672                 FuncStatus & status) const;
673         ///
674         void toggleFixedWidth(bool fw) { isFixedWidth = fw; }
675         ///
676         void setContentAlignment(LyXAlignment al) {contentAlign = al; }
677         /// writes the contents of the cell as a string, optionally
678         /// descending into insets
679         docstring asString(bool intoInsets = true);
680 private:
681         /// unimplemented
682         InsetTableCell();
683         /// unimplemented
684         void operator=(InsetTableCell const &);
685         // FIXME
686         // This boolean is supposed to track whether the cell has had its
687         // width explicitly set. We need to know this to determine whether
688         // layout changes and paragraph customization are allowed---that is,
689         // we need it in forcePlainLayout() and allowParagraphCustomization(). 
690         // Unfortunately, that information is not readily available in 
691         // InsetTableCell. In the case of multicolumn cells, it is present
692         // in CellData, and so would be available here if CellData were to
693         // become a member of InsetTableCell. But in the other case, it isn't
694         // even available there, but is held in Tabular::ColumnData.
695         // So, the present solution uses this boolean to track the information
696         // we need to track, and tries to keep it updated. This is not ideal,
697         // but the other solutions are no better. These are:
698         // (i)  Keep a pointer in InsetTableCell to the table;
699         // (ii) Find the table by iterating over the Buffer's insets.
700         // Solution (i) raises the problem of updating the pointer when an 
701         // InsetTableCell is copied, and we'd therefore need a copy constructor
702         // in InsetTabular and then in Tabular, which seems messy, given how 
703         // complicated those classes are. Solution (ii) involves a lot of 
704         // iterating, since this information is needed quite often, and so may
705         // be quite slow.
706         // So, well, if someone can do better, please do!
707         // --rgh
708         ///
709         bool isFixedWidth;
710         // FIXME: Here the thoughts from the comment above also apply.
711         ///
712         LyXAlignment contentAlign;
713         /// should paragraph indendation be omitted in any case?
714         bool neverIndent() const { return true; }
715         ///
716         LyXAlignment contentAlignment() const { return contentAlign; }
717         ///
718         virtual bool usePlainLayout() const { return true; }
719         /// 
720         virtual bool forcePlainLayout(idx_type = 0) const;
721         /// 
722         virtual bool allowParagraphCustomization(idx_type = 0) const;
723         /// Is the width forced to some value?
724         bool hasFixedWidth() const { return isFixedWidth; }
725 };
726
727
728 class InsetTabular : public Inset
729 {
730 public:
731         ///
732         InsetTabular(Buffer &, row_type rows = 1,
733                      col_type columns = 1);
734         ///
735         ~InsetTabular();
736         ///
737         void setBuffer(Buffer & buffer);
738
739         ///
740         static void string2params(std::string const &, InsetTabular &);
741         ///
742         static std::string params2string(InsetTabular const &);
743         ///
744         void read(Lexer &);
745         ///
746         void write(std::ostream &) const;
747         ///
748         void metrics(MetricsInfo &, Dimension &) const;
749         ///
750         void draw(PainterInfo & pi, int x, int y) const;
751         ///
752         void drawSelection(PainterInfo & pi, int x, int y) const;
753         ///
754         bool editable() const { return true; }
755         ///
756         bool hasSettings() const { return true; }
757         ///
758         bool insetAllowed(InsetCode code) const;
759         ///
760         bool allowSpellCheck() const { return true; }
761         ///
762         bool canTrackChanges() const { return true; }
763         /** returns true if, when outputing LaTeX, font changes should
764             be closed before generating this inset. This is needed for
765             insets that may contain several paragraphs */
766         bool noFontChange() const { return true; }
767         ///
768         DisplayType display() const;
769         ///
770         int latex(odocstream &, OutputParams const &) const;
771         ///
772         int plaintext(odocstream &, OutputParams const &) const;
773         ///
774         int docbook(odocstream &, OutputParams const &) const;
775         ///
776         void validate(LaTeXFeatures & features) const;
777         ///
778         InsetCode lyxCode() const { return TABULAR_CODE; }
779         ///
780         docstring contextMenu(BufferView const & bv, int x, int y) const;
781         /// get offset of this cursor slice relative to our upper left corner
782         void cursorPos(BufferView const & bv, CursorSlice const & sl,
783                 bool boundary, int & x, int & y) const;
784         ///
785         bool tabularFeatures(Cursor & cur, std::string const & what);
786         ///
787         void tabularFeatures(Cursor & cur, Tabular::Feature feature,
788                              std::string const & val = std::string());
789         ///
790         void openLayoutDialog(BufferView *) const;
791         ///
792         bool showInsetDialog(BufferView *) const;
793         /// number of cells
794         size_t nargs() const { return tabular.numberofcells; }
795         ///
796         boost::shared_ptr<InsetTableCell const> cell(idx_type) const;
797         ///
798         boost::shared_ptr<InsetTableCell> cell(idx_type);
799         ///
800         Text * getText(int) const;
801
802         /// set the change for the entire inset
803         void setChange(Change const & change);
804         /// accept the changes within the inset
805         void acceptChanges();
806         /// reject the changes within the inset
807         void rejectChanges();
808
809         // this should return true if we have a "normal" cell, otherwise false.
810         // "normal" means without width set!
811         /// should all paragraphs be output with "Standard" layout?
812         virtual bool allowParagraphCustomization(idx_type cell = 0) const;
813         ///
814         virtual bool forcePlainLayout(idx_type cell = 0) const;
815         ///
816         void addPreview(graphics::PreviewLoader &) const;
817
818         /// lock cell with given index
819         void edit(Cursor & cur, bool front, EntryDirection entry_from);
820         /// get table row from x coordinate
821         int rowFromY(Cursor & cur, int y) const;
822         /// get table column from y coordinate
823         int columnFromX(Cursor & cur, int x) const;
824         ///
825         Inset * editXY(Cursor & cur, int x, int y);
826         /// can we go further down on mouse click?
827         bool descendable() const { return true; }
828         // Update the counters of this inset and of its contents
829         void updateLabels(ParIterator const &);
830
831         ///
832         bool completionSupported(Cursor const &) const;
833         ///
834         bool inlineCompletionSupported(Cursor const & cur) const;
835         ///
836         bool automaticInlineCompletion() const;
837         ///
838         bool automaticPopupCompletion() const;
839         ///
840         bool showCompletionCursor() const;
841         ///
842         CompletionList const * createCompletionList(Cursor const & cur) const;
843         ///
844         docstring completionPrefix(Cursor const & cur) const;
845         ///
846         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
847         ///
848         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
849         ///
850         virtual bool usePlainLayout() const { return true; }
851
852         ///
853         virtual InsetTabular * asInsetTabular() { return this; }
854         ///
855         virtual InsetTabular const * asInsetTabular() const { return this; }
856         ///
857         bool isRightToLeft(Cursor & cur) const;
858         /// writes the cells between stidx and enidx as a string, optionally
859         /// descending into the insets
860         docstring asString(idx_type stidx, idx_type enidx, bool intoInsets = true);
861
862         /// Returns whether the cell in the specified row and column is selected.
863         bool isCellSelected(Cursor & cur, row_type row, col_type col) const;
864         //
865         // Public structures and variables
866         ///
867         mutable Tabular tabular;
868
869 private:
870         ///
871         InsetTabular(InsetTabular const &);
872         ///
873         void doDispatch(Cursor & cur, FuncRequest & cmd);
874         ///
875         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
876         ///
877         int scroll() const { return scx_; }
878         ///
879         Inset * clone() const { return new InsetTabular(*this); }
880
881         ///
882         void drawCellLines(frontend::Painter &, int x, int y, row_type row,
883                            idx_type cell, Change const & change) const;
884         ///
885         void setCursorFromCoordinates(Cursor & cur, int x, int y) const;
886
887         ///
888         void moveNextCell(Cursor & cur, 
889                                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
890         ///
891         void movePrevCell(Cursor & cur,
892                                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
893         ///
894         int cellXPos(idx_type cell) const;
895         ///
896         void resetPos(Cursor & cur) const;
897         ///
898         void removeTabularRow();
899         ///
900         bool copySelection(Cursor & cur);
901         ///
902         bool pasteClipboard(Cursor & cur);
903         ///
904         void cutSelection(Cursor & cur);
905         ///
906         void getSelection(Cursor & cur, row_type & rs, row_type & re,
907                           col_type & cs, col_type & ce) const;
908         ///
909         bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
910
911         /// return the "Manhattan distance" to nearest corner
912         int dist(BufferView &, idx_type cell, int x, int y) const;
913         /// return the cell nearest to x, y
914         idx_type getNearestCell(BufferView &, int x, int y) const;
915
916         /// test the rotation state of the give cell range.
917         bool oneCellHasRotationState(bool rotated,
918                                 row_type row_start, row_type row_end,
919                                 col_type col_start, col_type col_end) const;
920         ///
921         mutable idx_type first_visible_cell;
922         ///
923         mutable int scx_;
924         /// true when selecting rows with the mouse
925         bool rowselect_;
926         /// true when selecting columns with the mouse
927         bool colselect_;
928 };
929
930 std::string const featureAsString(Tabular::Feature feature);
931
932 } // namespace lyx
933
934 #endif // INSET_TABULAR_H