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