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