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