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