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