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