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