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