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