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