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