]> git.lyx.org Git - lyx.git/blob - src/insets/InsetTabular.h
e1760ad4e12ccae28c0fe462dbad6df7c3a618ff
[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 <boost/shared_ptr.hpp>
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 rowHeight(idx_type cell) const;
286         ///
287         int width() const;
288         ///
289         int height() const;
290         ///
291         int rowAscent(row_type row) const;
292         ///
293         int rowDescent(row_type row) const;
294         ///
295         void setRowAscent(row_type row, int height);
296         ///
297         void setRowDescent(row_type row, int height);
298         ///
299         void setCellWidth(idx_type cell, int new_width);
300         ///
301         void setTopLine(idx_type cell, bool line);
302         ///
303         void setBottomLine(idx_type cell, bool line);
304         ///
305         void setLeftLine(idx_type cell, bool line);
306         ///
307         void setRightLine(idx_type cell, bool line);
308         ///
309         bool rowTopLine(row_type row) const;
310         ///
311         bool rowBottomLine(row_type row) const;
312         ///
313         bool columnLeftLine(col_type column) const;
314         ///
315         bool columnRightLine(col_type column) const;
316
317         void setAlignment(idx_type cell, LyXAlignment align,
318                           bool onlycolumn = false);
319         ///
320         void setVAlignment(idx_type cell, VAlignment align,
321                            bool onlycolumn = false);
322         ///
323         void setColumnPWidth(Cursor &, idx_type, Length const &);
324         ///
325         bool setMColumnPWidth(Cursor &, idx_type, Length const &);
326         ///
327         void setAlignSpecial(idx_type cell, docstring const & special,
328                              Feature what);
329         ///
330         LyXAlignment getAlignment(idx_type cell,
331                                   bool onlycolumn = false) const;
332         ///
333         VAlignment getVAlignment(idx_type cell,
334                                  bool onlycolumn = false) const;
335         ///
336         Length const getPWidth(idx_type cell) const;
337         ///
338         int cellWidth(idx_type cell) const;
339         ///
340         int textHOffset(idx_type cell) const;
341         ///
342         int textVOffset(idx_type cell) const;
343         ///
344         void appendRow(idx_type cell);
345         ///
346         void deleteRow(row_type row);
347         ///
348         void copyRow(row_type);
349         ///
350         void appendColumn(idx_type cell);
351         ///
352         void deleteColumn(col_type column);
353         ///
354         void copyColumn(col_type);
355         ///
356         idx_type getFirstCellInRow(row_type row) const;
357         ///
358         idx_type getLastCellInRow(row_type row) const;
359         ///
360         idx_type numberOfCellsInRow(row_type row) const;
361         ///
362         void write(std::ostream &) const;
363         ///
364         void read(Lexer &);
365         ///
366         int latex(odocstream &, OutputParams const &) const;
367         ///
368         int docbook(odocstream & os, OutputParams const &) const;
369         ///
370         docstring xhtml(XHTMLStream & os, OutputParams const &) const;
371         ///
372         void plaintext(odocstream &,
373                        OutputParams const & runparams, int const depth,
374                        bool onlydata, char_type delim) const;
375         ///
376         bool isMultiColumn(idx_type cell) const;
377         ///
378         void setMultiColumn(idx_type cell, idx_type number);
379         ///
380         void unsetMultiColumn(idx_type cell);
381         ///
382         bool isPartOfMultiColumn(row_type row, col_type column) const;
383         ///
384         bool isPartOfMultiRow(row_type row, col_type column) const;
385         ///
386         bool isMultiRow(idx_type cell) const;
387         ///
388         void setMultiRow(idx_type cell, idx_type number);
389         ///
390         void unsetMultiRow(idx_type cell);
391         ///
392         row_type cellRow(idx_type cell) const;
393         ///
394         col_type cellColumn(idx_type cell) const;
395         ///
396         void setRotateCell(idx_type cell, bool);
397         ///
398         bool getRotateCell(idx_type cell) const;
399         ///
400         bool needRotating() const;
401         ///
402         bool isLastCell(idx_type cell) const;
403         ///
404         idx_type cellAbove(idx_type cell) const;
405         ///
406         idx_type cellBelow(idx_type cell) const;
407         ///
408         idx_type cellIndex(row_type row, col_type column) const;
409         ///
410         void setUsebox(idx_type cell, BoxType);
411         ///
412         BoxType getUsebox(idx_type cell) const;
413         //
414         // Long Tabular Options support functions
415         ///
416         bool checkLTType(row_type row, ltType const &) const;
417         ///
418         void setLTHead(row_type row, bool flag, ltType const &, bool first);
419         ///
420         bool getRowOfLTHead(row_type row, ltType &) const;
421         ///
422         bool getRowOfLTFirstHead(row_type row, ltType &) const;
423         ///
424         void setLTFoot(row_type row, bool flag, ltType const &, bool last);
425         ///
426         bool getRowOfLTFoot(row_type row, ltType &) const;
427         ///
428         bool getRowOfLTLastFoot(row_type row, ltType &) const;
429         ///
430         void setLTNewPage(row_type row, bool what);
431         ///
432         bool getLTNewPage(row_type row) const;
433         ///
434         idx_type setLTCaption(row_type row, bool what);
435         ///
436         bool ltCaption(row_type row) const;
437         ///
438         bool haveLTHead() const;
439         ///
440         bool haveLTFirstHead() const;
441         ///
442         bool haveLTFoot() const;
443         ///
444         bool haveLTLastFoot() const;
445         ///
446         bool haveLTCaption() const;
447         ///
448         // end longtable support
449         ///
450         boost::shared_ptr<InsetTableCell> cellInset(idx_type cell) const;
451         ///
452         boost::shared_ptr<InsetTableCell> cellInset(row_type row,
453                                                   col_type column) const;
454         ///
455         void setCellInset(row_type row, col_type column,
456                           boost::shared_ptr<InsetTableCell>) const;
457         /// Search for \param inset in the tabular, with the
458         ///
459         void validate(LaTeXFeatures &) const;
460 //private:
461   // FIXME Now that cells have an InsetTableCell as their insets, rather
462   // than an InsetText, it'd be possible to reverse the relationship here,
463   // so that cell_vector was a vector<InsetTableCell> rather than a 
464   // vector<CellData>, and an InsetTableCell had a CellData as a member,
465   // or perhaps just had its members as members.
466         ///
467         class CellData {
468         public:
469                 ///
470                 CellData(Buffer *);
471                 ///
472                 CellData(CellData const &);
473                 ///
474                 CellData & operator=(CellData);
475                 ///
476                 void swap(CellData & rhs);
477                 ///
478                 idx_type cellno;
479                 ///
480                 int width;
481                 ///
482                 int multicolumn;
483                 ///
484                 int multirow;
485                 ///
486                 LyXAlignment alignment;
487                 ///
488                 VAlignment valignment;
489                 ///
490                 bool top_line;
491                 ///
492                 bool bottom_line;
493                 ///
494                 bool left_line;
495                 ///
496                 bool right_line;
497                 ///
498                 BoxType usebox;
499                 ///
500                 bool rotate;
501                 ///
502                 docstring align_special;
503                 ///
504                 Length p_width; // this is only set for multicolumn!!!
505                 ///
506                 boost::shared_ptr<InsetTableCell> inset;
507         };
508         CellData & cellInfo(idx_type cell) const;
509         ///
510         typedef std::vector<CellData> cell_vector;
511         ///
512         typedef std::vector<cell_vector> cell_vvector;
513
514         ///
515         class RowData {
516         public:
517                 ///
518                 RowData();
519                 ///
520                 int ascent;
521                 ///
522                 int descent;
523                 /// Extra space between the top line and this row
524                 Length top_space;
525                 /// Ignore top_space if true and use the default top space
526                 bool top_space_default;
527                 /// Extra space between this row and the bottom line
528                 Length bottom_space;
529                 /// Ignore bottom_space if true and use the default bottom space
530                 bool bottom_space_default;
531                 /// Extra space between the bottom line and the next top line
532                 Length interline_space;
533                 /// Ignore interline_space if true and use the default interline space
534                 bool interline_space_default;
535                 /// This are for longtabulars only
536                 /// a row of endhead
537                 bool endhead;
538                 /// a row of endfirsthead
539                 bool endfirsthead;
540                 /// a row of endfoot
541                 bool endfoot;
542                 /// row of endlastfoot
543                 bool endlastfoot;
544                 /// row for a newpage
545                 bool newpage;
546                 /// caption
547                 bool caption;
548         };
549         ///
550         typedef std::vector<RowData> row_vector;
551
552         ///
553         class ColumnData {
554                 public:
555                 ///
556                 ColumnData();
557                 ///
558                 LyXAlignment alignment;
559                 ///
560                 VAlignment valignment;
561                 ///
562                 int width;
563                 ///
564                 Length p_width;
565                 ///
566                 docstring align_special;
567         };
568         ///
569         typedef std::vector<ColumnData> column_vector;
570
571         ///
572         idx_type numberofcells;
573         ///
574         std::vector<row_type> rowofcell;
575         ///
576         std::vector<col_type> columnofcell;
577         ///
578         row_vector row_info;
579         ///
580         column_vector column_info;
581         ///
582         mutable cell_vvector cell_info;
583         ///
584         bool use_booktabs;
585         ///
586         bool rotate;
587         ///
588         VAlignment tabular_valignment;
589         //
590         // for long tabulars
591         ///
592         HAlignment longtabular_alignment;
593         //
594         bool is_long_tabular;
595         /// endhead data
596         ltType endhead;
597         /// endfirsthead data
598         ltType endfirsthead;
599         /// endfoot data
600         ltType endfoot;
601         /// endlastfoot data
602         ltType endlastfoot;
603
604         ///
605         void init(Buffer *, row_type rows_arg,
606                   col_type columns_arg);
607         ///
608         void updateIndexes();
609         ///
610         bool setFixedWidth(row_type r, col_type c);
611         ///
612         void updateContentAlignment(row_type r, col_type c);
613         /// return true of update is needed
614         bool updateColumnWidths();
615         ///
616         idx_type columnSpan(idx_type cell) const;
617         ///
618         idx_type rowSpan(idx_type cell) const;
619         ///
620         BoxType useParbox(idx_type cell) const;
621         ///
622         // helper function for Latex returns number of newlines
623         ///
624         int TeXTopHLine(odocstream &, row_type row, std::string const lang) const;
625         ///
626         int TeXBottomHLine(odocstream &, row_type row, std::string const lang) const;
627         ///
628         int TeXCellPreamble(odocstream &, idx_type cell, bool & ismulticol, bool & ismultirow) const;
629         ///
630         int TeXCellPostamble(odocstream &, idx_type cell, bool ismulticol, bool ismultirow) const;
631         ///
632         int TeXLongtableHeaderFooter(odocstream &, OutputParams const &) const;
633         ///
634         bool isValidRow(row_type const row) const;
635         ///
636         int TeXRow(odocstream &, row_type const row,
637                    OutputParams const &) const;
638         ///
639         // helper functions for plain text
640         ///
641         bool plaintextTopHLine(odocstream &, row_type row,
642                                std::vector<unsigned int> const &) const;
643         ///
644         bool plaintextBottomHLine(odocstream &, row_type row,
645                                   std::vector<unsigned int> const &) const;
646         ///
647         void plaintextPrintCell(odocstream &,
648                                 OutputParams const &,
649                                 idx_type cell, row_type row, col_type column,
650                                 std::vector<unsigned int> const &,
651                                 bool onlydata) const;
652         /// auxiliary function for docbook
653         int docbookRow(odocstream & os, row_type, OutputParams const &) const;
654         ///
655         docstring xhtmlRow(XHTMLStream & xs, row_type, OutputParams const &) const;
656
657         /// change associated Buffer
658         void setBuffer(Buffer & buffer);
659         /// retrieve associated Buffer
660         Buffer & buffer() const { return *buffer_; }
661
662 private:
663         Buffer * buffer_;
664
665 }; // Tabular
666
667
668 ///
669 class InsetTableCell : public InsetText
670 {
671 public:
672         ///
673         InsetTableCell(Buffer * buf);
674         ///
675         InsetCode lyxCode() const { return CELL_CODE; }
676         ///
677         Inset * clone() { return new InsetTableCell(*this); }
678         ///
679         bool getStatus(Cursor & cur, FuncRequest const & cmd,
680                 FuncStatus & status) const;
681         ///
682         void toggleFixedWidth(bool fw) { isFixedWidth = fw; }
683         ///
684         void setContentAlignment(LyXAlignment al) {contentAlign = al; }
685         /// writes the contents of the cell as a string, optionally
686         /// descending into insets
687         docstring asString(bool intoInsets = true);
688         ///
689         docstring xhtml(XHTMLStream &, OutputParams const &) const;
690 private:
691         /// unimplemented
692         InsetTableCell();
693         /// unimplemented
694         void operator=(InsetTableCell const &);
695         // FIXME
696         // This boolean is supposed to track whether the cell has had its
697         // width explicitly set. We need to know this to determine whether
698         // layout changes and paragraph customization are allowed---that is,
699         // we need it in forcePlainLayout() and allowParagraphCustomization(). 
700         // Unfortunately, that information is not readily available in 
701         // InsetTableCell. In the case of multicolumn cells, it is present
702         // in CellData, and so would be available here if CellData were to
703         // become a member of InsetTableCell. But in the other case, it isn't
704         // even available there, but is held in Tabular::ColumnData.
705         // So, the present solution uses this boolean to track the information
706         // we need to track, and tries to keep it updated. This is not ideal,
707         // but the other solutions are no better. These are:
708         // (i)  Keep a pointer in InsetTableCell to the table;
709         // (ii) Find the table by iterating over the Buffer's insets.
710         // Solution (i) raises the problem of updating the pointer when an 
711         // InsetTableCell is copied, and we'd therefore need a copy constructor
712         // in InsetTabular and then in Tabular, which seems messy, given how 
713         // complicated those classes are. Solution (ii) involves a lot of 
714         // iterating, since this information is needed quite often, and so may
715         // be quite slow.
716         // So, well, if someone can do better, please do!
717         // --rgh
718         ///
719         bool isFixedWidth;
720         // FIXME: Here the thoughts from the comment above also apply.
721         ///
722         LyXAlignment contentAlign;
723         /// should paragraph indendation be omitted in any case?
724         bool neverIndent() const { return true; }
725         ///
726         LyXAlignment contentAlignment() const { return contentAlign; }
727         ///
728         virtual bool usePlainLayout() const { return true; }
729         /// 
730         virtual bool forcePlainLayout(idx_type = 0) const;
731         /// 
732         virtual bool allowParagraphCustomization(idx_type = 0) const;
733         /// Is the width forced to some value?
734         bool hasFixedWidth() const { return isFixedWidth; }
735 };
736
737
738 class InsetTabular : public Inset
739 {
740 public:
741         ///
742         InsetTabular(Buffer *, row_type rows = 1,
743                      col_type columns = 1);
744         ///
745         ~InsetTabular();
746         ///
747         void setBuffer(Buffer & buffer);
748
749         ///
750         static void string2params(std::string const &, InsetTabular &);
751         ///
752         static std::string params2string(InsetTabular const &);
753         ///
754         void read(Lexer &);
755         ///
756         void write(std::ostream &) const;
757         ///
758         void metrics(MetricsInfo &, Dimension &) const;
759         ///
760         void draw(PainterInfo & pi, int x, int y) const;
761         ///
762         void drawSelection(PainterInfo & pi, int x, int y) const;
763         ///
764         bool editable() const { return true; }
765         ///
766         bool hasSettings() const { return true; }
767         ///
768         bool insetAllowed(InsetCode code) const;
769         ///
770         bool allowSpellCheck() const { return true; }
771         ///
772         bool canTrackChanges() const { return true; }
773         /** returns true if, when outputing LaTeX, font changes should
774             be closed before generating this inset. This is needed for
775             insets that may contain several paragraphs */
776         bool noFontChange() const { return true; }
777         ///
778         DisplayType display() const;
779         ///
780         int latex(odocstream &, OutputParams const &) const;
781         ///
782         int plaintext(odocstream &, OutputParams const &) const;
783         ///
784         int docbook(odocstream &, OutputParams const &) const;
785         ///
786         docstring xhtml(XHTMLStream &, OutputParams const &) const;
787         ///
788         void validate(LaTeXFeatures & features) const;
789         ///
790         InsetCode lyxCode() const { return TABULAR_CODE; }
791         ///
792         docstring contextMenu(BufferView const & bv, int x, int y) const;
793         /// get offset of this cursor slice relative to our upper left corner
794         void cursorPos(BufferView const & bv, CursorSlice const & sl,
795                 bool boundary, int & x, int & y) const;
796         ///
797         bool tabularFeatures(Cursor & cur, std::string const & what);
798         ///
799         void tabularFeatures(Cursor & cur, Tabular::Feature feature,
800                              std::string const & val = std::string());
801         /// number of cells
802         size_t nargs() const { return tabular.numberofcells; }
803         ///
804         boost::shared_ptr<InsetTableCell const> cell(idx_type) const;
805         ///
806         boost::shared_ptr<InsetTableCell> cell(idx_type);
807         ///
808         Text * getText(int) const;
809
810         /// set the change for the entire inset
811         void setChange(Change const & change);
812         /// accept the changes within the inset
813         void acceptChanges();
814         /// reject the changes within the inset
815         void rejectChanges();
816
817         // this should return true if we have a "normal" cell, otherwise false.
818         // "normal" means without width set!
819         /// should all paragraphs be output with "Standard" layout?
820         virtual bool allowParagraphCustomization(idx_type cell = 0) const;
821         ///
822         virtual bool forcePlainLayout(idx_type cell = 0) const;
823         ///
824         void addPreview(DocIterator const & inset_pos,
825                 graphics::PreviewLoader &) const;
826
827         /// lock cell with given index
828         void edit(Cursor & cur, bool front, EntryDirection entry_from);
829         /// get table row from x coordinate
830         int rowFromY(Cursor & cur, int y) const;
831         /// get table column from y coordinate
832         int columnFromX(Cursor & cur, int x) const;
833         ///
834         Inset * editXY(Cursor & cur, int x, int y);
835         /// can we go further down on mouse click?
836         bool descendable(BufferView const &) const { return true; }
837         /// Update the counters of this inset and of its contents
838         void updateBuffer(ParIterator const &, UpdateType);
839         ///
840         void addToToc(DocIterator const &);
841
842         ///
843         bool completionSupported(Cursor const &) const;
844         ///
845         bool inlineCompletionSupported(Cursor const & cur) const;
846         ///
847         bool automaticInlineCompletion() const;
848         ///
849         bool automaticPopupCompletion() const;
850         ///
851         bool showCompletionCursor() const;
852         ///
853         CompletionList const * createCompletionList(Cursor const & cur) const;
854         ///
855         docstring completionPrefix(Cursor const & cur) const;
856         ///
857         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
858         ///
859         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
860         ///
861         virtual bool usePlainLayout() const { return true; }
862
863         ///
864         virtual InsetTabular * asInsetTabular() { return this; }
865         ///
866         virtual InsetTabular const * asInsetTabular() const { return this; }
867         ///
868         bool isRightToLeft(Cursor & cur) const;
869         /// writes the cells between stidx and enidx as a string, optionally
870         /// descending into the insets
871         docstring asString(idx_type stidx, idx_type enidx, bool intoInsets = true);
872
873         /// Returns whether the cell in the specified row and column is selected.
874         bool isCellSelected(Cursor & cur, row_type row, col_type col) const;
875         //
876         // Public structures and variables
877         ///
878         mutable Tabular tabular;
879
880 private:
881         ///
882         InsetTabular(InsetTabular const &);
883         ///
884         void doDispatch(Cursor & cur, FuncRequest & cmd);
885         ///
886         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
887         ///
888         int scroll() const { return scx_; }
889         ///
890         Inset * clone() const { return new InsetTabular(*this); }
891
892         ///
893         void drawCellLines(frontend::Painter &, int x, int y, row_type row,
894                            idx_type cell, Change const & change) const;
895         ///
896         void setCursorFromCoordinates(Cursor & cur, int x, int y) const;
897
898         ///
899         void moveNextCell(Cursor & cur, 
900                                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
901         ///
902         void movePrevCell(Cursor & cur,
903                                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
904         ///
905         int cellXPos(idx_type cell) const;
906         ///
907         void resetPos(Cursor & cur) const;
908         ///
909         void removeTabularRow();
910         ///
911         bool copySelection(Cursor & cur);
912         ///
913         bool pasteClipboard(Cursor & cur);
914         ///
915         void cutSelection(Cursor & cur);
916         ///
917         void getSelection(Cursor & cur, row_type & rs, row_type & re,
918                           col_type & cs, col_type & ce) const;
919         ///
920         bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
921
922         /// return the "Manhattan distance" to nearest corner
923         int dist(BufferView &, idx_type cell, int x, int y) const;
924         /// return the cell nearest to x, y
925         idx_type getNearestCell(BufferView &, int x, int y) const;
926
927         /// test the rotation state of the give cell range.
928         bool oneCellHasRotationState(bool rotated,
929                                 row_type row_start, row_type row_end,
930                                 col_type col_start, col_type col_end) const;
931         ///
932         mutable idx_type first_visible_cell;
933         ///
934         mutable int scx_;
935         /// true when selecting rows with the mouse
936         bool rowselect_;
937         /// true when selecting columns with the mouse
938         bool colselect_;
939 };
940
941 std::string const featureAsString(Tabular::Feature feature);
942
943 } // namespace lyx
944
945 #endif // INSET_TABULAR_H