]> git.lyx.org Git - lyx.git/blob - src/insets/InsetTabular.h
d529793016411e36adab4fb40b74055aa24bcf08
[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 CursorSlice;
42 class InsetTableCell;
43 class FuncStatus;
44 class Lexer;
45 class Paragraph;
46 class XHTMLStream;
47
48 namespace frontend { class Painter; }
49
50
51 class InsetTabular;
52 class Cursor;
53 class OutputParams;
54
55 //
56 // A helper struct for tables
57 //
58 class Tabular {
59 public:
60         ///
61         enum Feature {
62                 ///
63                 APPEND_ROW = 0,
64                 ///
65                 APPEND_COLUMN,
66                 ///
67                 DELETE_ROW,
68                 ///
69                 DELETE_COLUMN,
70                 ///
71                 COPY_ROW,
72                 ///
73                 COPY_COLUMN,
74                 ///
75                 SET_LINE_TOP,
76                 ///
77                 SET_LINE_BOTTOM,
78                 ///
79                 SET_LINE_LEFT,
80                 ///
81                 SET_LINE_RIGHT,
82                 ///FIXME: remove
83                 TOGGLE_LINE_TOP,
84                 ///FIXME: remove
85                 TOGGLE_LINE_BOTTOM,
86                 ///FIXME: remove
87                 TOGGLE_LINE_LEFT,
88                 ///FIXME: remove
89                 TOGGLE_LINE_RIGHT,
90                 ///
91                 ALIGN_LEFT,
92                 ///
93                 ALIGN_RIGHT,
94                 ///
95                 ALIGN_CENTER,
96                 ///
97                 ALIGN_BLOCK,
98                 ///
99                 ALIGN_DECIMAL,
100                 ///
101                 VALIGN_TOP,
102                 ///
103                 VALIGN_BOTTOM,
104                 ///
105                 VALIGN_MIDDLE,
106                 ///
107                 M_ALIGN_LEFT,
108                 ///
109                 M_ALIGN_RIGHT,
110                 ///
111                 M_ALIGN_CENTER,
112                 ///
113                 M_VALIGN_TOP,
114                 ///
115                 M_VALIGN_BOTTOM,
116                 ///
117                 M_VALIGN_MIDDLE,
118                 ///
119                 MULTICOLUMN,
120                 ///
121                 MULTIROW,
122                 ///
123                 SET_ALL_LINES,
124                 ///
125                 UNSET_ALL_LINES,
126                 ///
127                 SET_LONGTABULAR,
128                 ///
129                 UNSET_LONGTABULAR,
130                 ///
131                 SET_PWIDTH,
132                 ///
133                 SET_MPWIDTH,
134                 ///
135                 SET_ROTATE_TABULAR,
136                 ///
137                 UNSET_ROTATE_TABULAR,
138                 ///
139                 TOGGLE_ROTATE_TABULAR,
140                 ///
141                 SET_ROTATE_CELL,
142                 ///
143                 UNSET_ROTATE_CELL,
144                 ///
145                 TOGGLE_ROTATE_CELL,
146                 ///
147                 SET_USEBOX,
148                 ///
149                 SET_LTHEAD,
150                 UNSET_LTHEAD,
151                 ///
152                 SET_LTFIRSTHEAD,
153                 UNSET_LTFIRSTHEAD,
154                 ///
155                 SET_LTFOOT,
156                 UNSET_LTFOOT,
157                 ///
158                 SET_LTLASTFOOT,
159                 UNSET_LTLASTFOOT,
160                 ///
161                 SET_LTNEWPAGE,
162                 ///
163                 TOGGLE_LTCAPTION,
164                 ///
165                 SET_SPECIAL_COLUMN,
166                 ///
167                 SET_SPECIAL_MULTICOLUMN,
168                 ///
169                 SET_SPECIAL_MULTIROW,
170                 ///
171                 SET_BOOKTABS,
172                 ///
173                 UNSET_BOOKTABS,
174                 ///
175                 SET_TOP_SPACE,
176                 ///
177                 SET_BOTTOM_SPACE,
178                 ///
179                 SET_INTERLINE_SPACE,
180                 ///
181                 SET_BORDER_LINES,
182                 ///
183                 TABULAR_VALIGN_TOP,
184                 ///
185                 TABULAR_VALIGN_MIDDLE,
186                 ///
187                 TABULAR_VALIGN_BOTTOM,
188                 ///
189                 LONGTABULAR_ALIGN_LEFT,
190                 ///
191                 LONGTABULAR_ALIGN_CENTER,
192                 ///
193                 LONGTABULAR_ALIGN_RIGHT,
194                 ///
195                 SET_DECIMAL_POINT,
196                 ///
197                 LAST_ACTION
198         };
199         ///
200         enum {
201                 ///
202                 CELL_NORMAL = 0,
203                 ///
204                 CELL_BEGIN_OF_MULTICOLUMN,
205                 ///
206                 CELL_PART_OF_MULTICOLUMN,
207                 ///
208                 CELL_BEGIN_OF_MULTIROW,
209                 ///
210                 CELL_PART_OF_MULTIROW
211         };
212
213         ///
214         enum VAlignment {
215                 ///
216                 LYX_VALIGN_TOP = 0,
217                 ///
218                 LYX_VALIGN_MIDDLE = 1,
219                 ///
220                 LYX_VALIGN_BOTTOM = 2
221                 
222         };
223         ///
224         enum HAlignment {
225                 ///
226                 LYX_LONGTABULAR_ALIGN_LEFT = 0,
227                 ///
228                 LYX_LONGTABULAR_ALIGN_CENTER = 1,
229                 ///
230                 LYX_LONGTABULAR_ALIGN_RIGHT = 2
231         };
232
233         enum BoxType {
234                 ///
235                 BOX_NONE = 0,
236                 ///
237                 BOX_PARBOX = 1,
238                 ///
239                 BOX_MINIPAGE = 2
240         };
241
242         class ltType {
243         public:
244                 // constructor
245                 ltType();
246                 // we have this header type (is set in the getLT... functions)
247                 bool set;
248                 // double borders on top
249                 bool topDL;
250                 // double borders on bottom
251                 bool bottomDL;
252                 // used for FirstHeader & LastFooter and if this is true
253                 // all the rows marked as FirstHeader or LastFooter are
254                 // ignored in the output and it is set to be empty!
255                 bool empty;
256         };
257
258         /// type for row numbers
259         typedef size_t row_type;
260         /// type for column numbers
261         typedef size_t col_type;
262         /// type for cell indices
263         typedef size_t idx_type;
264         /// index indicating an invalid position
265         static const idx_type npos = static_cast<idx_type>(-1);
266
267         /// constructor
268         Tabular(Buffer * buf, col_type columns_arg, row_type rows_arg);
269
270         /// Returns true if there is a topline, returns false if not
271         bool topLine(idx_type cell) const;
272         /// Returns true if there is a topline, returns false if not
273         bool bottomLine(idx_type cell) const;
274         /// Returns true if there is a topline, returns false if not
275         bool leftLine(idx_type cell) const;
276         /// Returns true if there is a topline, returns false if not
277         bool rightLine(idx_type cell) const;
278
279         /// return space occupied by the second horizontal line and
280         /// interline space above row \p row in pixels
281         int interRowSpace(row_type row) const;
282         ///
283         int interColumnSpace(idx_type cell) const;
284
285         /* returns the maximum over all rows */
286         ///
287         int columnWidth(idx_type cell) const;
288         ///
289         int cellHeight(idx_type cell) const;
290         ///
291         int width() const;
292         ///
293         int height() const;
294         ///
295         row_type nrows() const {return row_info.size();}
296         ///
297         col_type ncols() const {return column_info.size();}
298         ///
299         int rowAscent(row_type row) const;
300         ///
301         int rowDescent(row_type row) const;
302         ///
303         void setRowAscent(row_type row, int height);
304         ///
305         void setRowDescent(row_type row, int height);
306         ///
307         void setCellWidth(idx_type cell, int new_width);
308         ///
309         void setTopLine(idx_type cell, bool line);
310         ///
311         void setBottomLine(idx_type cell, bool line);
312         ///
313         void setLeftLine(idx_type cell, bool line);
314         ///
315         void setRightLine(idx_type cell, bool line);
316         ///
317         bool rowTopLine(row_type row) const;
318         ///
319         bool rowBottomLine(row_type row) const;
320         ///
321         bool columnLeftLine(col_type column) const;
322         ///
323         bool columnRightLine(col_type column) const;
324
325         void setAlignment(idx_type cell, LyXAlignment align,
326                           bool onlycolumn = false);
327         ///
328         void setVAlignment(idx_type cell, VAlignment align,
329                            bool onlycolumn = false);
330         ///
331         void setColumnPWidth(Cursor &, idx_type, Length const &);
332         ///
333         bool setMColumnPWidth(Cursor &, idx_type, Length const &);
334         ///
335         void setAlignSpecial(idx_type cell, docstring const & special,
336                              Feature what);
337         ///
338         LyXAlignment getAlignment(idx_type cell,
339                                   bool onlycolumn = false) const;
340         ///
341         VAlignment getVAlignment(idx_type cell,
342                                  bool onlycolumn = false) const;
343         ///
344         Length const getPWidth(idx_type cell) const;
345         ///
346         int cellWidth(idx_type cell) const;
347         ///
348         int textHOffset(idx_type cell) const;
349         ///
350         int textVOffset(idx_type cell) const;
351         ///
352         void appendRow(idx_type cell);
353         ///
354         void deleteRow(row_type row);
355         ///
356         void copyRow(row_type);
357         ///
358         void appendColumn(idx_type cell);
359         ///
360         void deleteColumn(col_type column);
361         ///
362         void copyColumn(col_type);
363         ///
364         idx_type getFirstCellInRow(row_type row) const;
365         ///
366         idx_type getLastCellInRow(row_type row) const;
367         ///
368         idx_type numberOfCellsInRow(row_type row) const;
369         ///
370         void write(std::ostream &) const;
371         ///
372         void read(Lexer &);
373         ///
374         int latex(odocstream &, OutputParams const &) const;
375         ///
376         int docbook(odocstream & os, OutputParams const &) const;
377         ///
378         docstring xhtml(XHTMLStream & os, OutputParams const &) const;
379         ///
380         void plaintext(odocstream &,
381                        OutputParams const & runparams, int const depth,
382                        bool onlydata, char_type delim) const;
383         ///
384         bool isMultiColumn(idx_type cell) const;
385         ///
386         idx_type setMultiColumn(idx_type cell, idx_type number);
387         ///
388         void unsetMultiColumn(idx_type cell);
389         ///
390         bool isPartOfMultiColumn(row_type row, col_type column) const;
391         ///
392         bool isPartOfMultiRow(row_type row, col_type column) const;
393         ///
394         bool isMultiRow(idx_type cell) const;
395         ///
396         idx_type setMultiRow(idx_type cell, idx_type number);
397         ///
398         void unsetMultiRow(idx_type cell);
399         ///
400         row_type cellRow(idx_type cell) const;
401         ///
402         col_type cellColumn(idx_type cell) const;
403         ///
404         void setRotateCell(idx_type cell, bool);
405         ///
406         bool getRotateCell(idx_type cell) const;
407         ///
408         bool needRotating() const;
409         ///
410         bool isLastCell(idx_type cell) const;
411         ///
412         idx_type cellAbove(idx_type cell) const;
413         ///
414         idx_type cellBelow(idx_type cell) const;
415         ///
416         idx_type cellIndex(row_type row, col_type column) const;
417         ///
418         void setUsebox(idx_type cell, BoxType);
419         ///
420         BoxType getUsebox(idx_type cell) const;
421         //
422         // Long Tabular Options support functions
423         ///
424         bool checkLTType(row_type row, ltType const &) const;
425         ///
426         void setLTHead(row_type row, bool flag, ltType const &, bool first);
427         ///
428         bool getRowOfLTHead(row_type row, ltType &) const;
429         ///
430         bool getRowOfLTFirstHead(row_type row, ltType &) const;
431         ///
432         void setLTFoot(row_type row, bool flag, ltType const &, bool last);
433         ///
434         bool getRowOfLTFoot(row_type row, ltType &) const;
435         ///
436         bool getRowOfLTLastFoot(row_type row, ltType &) const;
437         ///
438         void setLTNewPage(row_type row, bool what);
439         ///
440         bool getLTNewPage(row_type row) const;
441         ///
442         idx_type setLTCaption(row_type row, bool what);
443         ///
444         bool ltCaption(row_type row) const;
445         ///
446         bool haveLTHead() const;
447         ///
448         bool haveLTFirstHead() const;
449         ///
450         bool haveLTFoot() const;
451         ///
452         bool haveLTLastFoot() const;
453         ///
454         bool haveLTCaption() const;
455         ///
456         // end longtable support
457         ///
458         shared_ptr<InsetTableCell> cellInset(idx_type cell) const;
459         ///
460         shared_ptr<InsetTableCell> cellInset(row_type row,
461                                                   col_type column) const;
462         ///
463         void setCellInset(row_type row, col_type column,
464                           shared_ptr<InsetTableCell>) const;
465         /// Search for \param inset in the tabular, with the
466         ///
467         void validate(LaTeXFeatures &) const;
468 //private:
469   // FIXME Now that cells have an InsetTableCell as their insets, rather
470   // than an InsetText, it'd be possible to reverse the relationship here,
471   // so that cell_vector was a vector<InsetTableCell> rather than a 
472   // vector<CellData>, and an InsetTableCell had a CellData as a member,
473   // or perhaps just had its members as members.
474         ///
475         class CellData {
476         public:
477                 ///
478                 CellData(Buffer *);
479                 ///
480                 CellData(CellData const &);
481                 ///
482                 CellData & operator=(CellData);
483                 ///
484                 void swap(CellData & rhs);
485                 ///
486                 idx_type cellno;
487                 ///
488                 int width;
489                 ///
490                 int multicolumn;
491                 ///
492                 int multirow;
493                 ///
494                 LyXAlignment alignment;
495                 ///
496                 VAlignment valignment;
497                 /// width of the part before the decimal
498                 int decimal_hoffset;
499                 /// width of the decimal part
500                 int decimal_width;
501                 ///
502                 int voffset;
503                 ///
504                 bool top_line;
505                 ///
506                 bool bottom_line;
507                 ///
508                 bool left_line;
509                 ///
510                 bool right_line;
511                 ///
512                 BoxType usebox;
513                 ///
514                 bool rotate;
515                 ///
516                 docstring align_special;
517                 ///
518                 Length p_width; // this is only set for multicolumn!!!
519                 ///
520                 shared_ptr<InsetTableCell> inset;
521         };
522         CellData & cellInfo(idx_type cell) const;
523         ///
524         typedef std::vector<CellData> cell_vector;
525         ///
526         typedef std::vector<cell_vector> cell_vvector;
527
528         ///
529         class RowData {
530         public:
531                 ///
532                 RowData();
533                 ///
534                 int ascent;
535                 ///
536                 int descent;
537                 /// Extra space between the top line and this row
538                 Length top_space;
539                 /// Ignore top_space if true and use the default top space
540                 bool top_space_default;
541                 /// Extra space between this row and the bottom line
542                 Length bottom_space;
543                 /// Ignore bottom_space if true and use the default bottom space
544                 bool bottom_space_default;
545                 /// Extra space between the bottom line and the next top line
546                 Length interline_space;
547                 /// Ignore interline_space if true and use the default interline space
548                 bool interline_space_default;
549                 /// This are for longtabulars only
550                 /// a row of endhead
551                 bool endhead;
552                 /// a row of endfirsthead
553                 bool endfirsthead;
554                 /// a row of endfoot
555                 bool endfoot;
556                 /// row of endlastfoot
557                 bool endlastfoot;
558                 /// row for a newpage
559                 bool newpage;
560                 /// caption
561                 bool caption;
562         };
563         ///
564         typedef std::vector<RowData> row_vector;
565
566         ///
567         class ColumnData {
568                 public:
569                 ///
570                 ColumnData();
571                 ///
572                 LyXAlignment alignment;
573                 ///
574                 VAlignment valignment;
575                 ///
576                 int width;
577                 ///
578                 Length p_width;
579                 ///
580                 docstring align_special;
581                 ///
582                 docstring decimal_point;
583         };
584         ///
585         typedef std::vector<ColumnData> column_vector;
586
587         ///
588         idx_type numberofcells;
589         ///
590         std::vector<row_type> rowofcell;
591         ///
592         std::vector<col_type> columnofcell;
593         ///
594         row_vector row_info;
595         ///
596         column_vector column_info;
597         ///
598         mutable cell_vvector cell_info;
599         ///
600         bool use_booktabs;
601         ///
602         bool rotate;
603         ///
604         VAlignment tabular_valignment;
605         //
606         // for long tabulars
607         ///
608         HAlignment longtabular_alignment;
609         //
610         bool is_long_tabular;
611         /// endhead data
612         ltType endhead;
613         /// endfirsthead data
614         ltType endfirsthead;
615         /// endfoot data
616         ltType endfoot;
617         /// endlastfoot data
618         ltType endlastfoot;
619
620         ///
621         void init(Buffer *, row_type rows_arg,
622                   col_type columns_arg);
623         ///
624         void updateIndexes();
625         ///
626         bool setFixedWidth(row_type r, col_type c);
627         /// return true of update is needed
628         bool updateColumnWidths();
629         ///
630         idx_type columnSpan(idx_type cell) const;
631         ///
632         idx_type rowSpan(idx_type cell) const;
633         ///
634         BoxType useParbox(idx_type cell) const;
635         ///
636         // helper function for Latex returns number of newlines
637         ///
638         int TeXTopHLine(odocstream &, row_type row, std::string const lang) const;
639         ///
640         int TeXBottomHLine(odocstream &, row_type row, std::string const lang) const;
641         ///
642         int TeXCellPreamble(odocstream &, idx_type cell, bool & ismulticol, bool & ismultirow) const;
643         ///
644         int TeXCellPostamble(odocstream &, idx_type cell, bool ismulticol, bool ismultirow) const;
645         ///
646         int TeXLongtableHeaderFooter(odocstream &, OutputParams const &) const;
647         ///
648         bool isValidRow(row_type const row) const;
649         ///
650         int TeXRow(odocstream &, row_type const row,
651                    OutputParams const &) const;
652         ///
653         // helper functions for plain text
654         ///
655         bool plaintextTopHLine(odocstream &, row_type row,
656                                std::vector<unsigned int> const &) const;
657         ///
658         bool plaintextBottomHLine(odocstream &, row_type row,
659                                   std::vector<unsigned int> const &) const;
660         ///
661         void plaintextPrintCell(odocstream &,
662                                 OutputParams const &,
663                                 idx_type cell, row_type row, col_type column,
664                                 std::vector<unsigned int> const &,
665                                 bool onlydata) const;
666         /// auxiliary function for docbook
667         int docbookRow(odocstream & os, row_type, OutputParams const &) const;
668         ///
669         docstring xhtmlRow(XHTMLStream & xs, row_type, OutputParams const &) const;
670
671         /// change associated Buffer
672         void setBuffer(Buffer & buffer);
673         /// retrieve associated Buffer
674         Buffer & buffer() const { return *buffer_; }
675
676 private:
677         Buffer * buffer_;
678
679 }; // Tabular
680
681
682 ///
683 class InsetTableCell : public InsetText
684 {
685 public:
686         ///
687         InsetTableCell(Buffer * buf);
688         ///
689         InsetCode lyxCode() const { return CELL_CODE; }
690         ///
691         Inset * clone() { return new InsetTableCell(*this); }
692         ///
693         bool getStatus(Cursor & cur, FuncRequest const & cmd,
694                 FuncStatus & status) const;
695         ///
696         void toggleFixedWidth(bool fw) { isFixedWidth = fw; }
697         ///
698         void setContentAlignment(LyXAlignment al) {contentAlign = al; }
699         /// writes the contents of the cell as a string, optionally
700         /// descending into insets
701         docstring asString(bool intoInsets = true);
702         ///
703         docstring xhtml(XHTMLStream &, OutputParams const &) const;
704 private:
705         /// unimplemented
706         InsetTableCell();
707         /// unimplemented
708         void operator=(InsetTableCell const &);
709         // FIXME
710         // This boolean is supposed to track whether the cell has had its
711         // width explicitly set. We need to know this to determine whether
712         // layout changes and paragraph customization are allowed---that is,
713         // we need it in forcePlainLayout() and allowParagraphCustomization(). 
714         // Unfortunately, that information is not readily available in 
715         // InsetTableCell. In the case of multicolumn cells, it is present
716         // in CellData, and so would be available here if CellData were to
717         // become a member of InsetTableCell. But in the other case, it isn't
718         // even available there, but is held in Tabular::ColumnData.
719         // So, the present solution uses this boolean to track the information
720         // we need to track, and tries to keep it updated. This is not ideal,
721         // but the other solutions are no better. These are:
722         // (i)  Keep a pointer in InsetTableCell to the table;
723         // (ii) Find the table by iterating over the Buffer's insets.
724         // Solution (i) raises the problem of updating the pointer when an 
725         // InsetTableCell is copied, and we'd therefore need a copy constructor
726         // in InsetTabular and then in Tabular, which seems messy, given how 
727         // complicated those classes are. Solution (ii) involves a lot of 
728         // iterating, since this information is needed quite often, and so may
729         // be quite slow.
730         // So, well, if someone can do better, please do!
731         // --rgh
732         ///
733         bool isFixedWidth;
734         // FIXME: Here the thoughts from the comment above also apply.
735         ///
736         LyXAlignment contentAlign;
737         /// should paragraph indendation be omitted in any case?
738         bool neverIndent() const { return true; }
739         ///
740         LyXAlignment contentAlignment() const { return contentAlign; }
741         ///
742         virtual bool usePlainLayout() const { return true; }
743         /// 
744         virtual bool forcePlainLayout(idx_type = 0) const;
745         /// 
746         virtual bool allowParagraphCustomization(idx_type = 0) const;
747         /// Is the width forced to some value?
748         bool hasFixedWidth() const { return isFixedWidth; }
749 };
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(frontend::Painter &, int x, int y, row_type row,
908                            idx_type cell, Change const & change) 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