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