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