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