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