]> git.lyx.org Git - lyx.git/blob - src/insets/InsetTabular.h
Initialize recently added forceownlines_ bool
[lyx.git] / src / insets / InsetTabular.h
1 // -*- C++ -*-
2 /**
3  * \file InsetTabular.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Matthias Ettrich
9  * \author André Pönitz
10  * \author Jürgen Vigna
11  * \author Edwin Leuven
12  * \author Uwe Stöhr
13  * \author Scott Kostyshak
14  *
15  * Full author contact details are available in file CREDITS.
16  */
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 // - column styles
23
24 #ifndef INSET_TABULAR_H
25 #define INSET_TABULAR_H
26
27 #include "Inset.h"
28 #include "InsetText.h"
29 #include "Length.h"
30
31 #include "support/shared_ptr.h"
32
33 #include <climits>
34 #include <iosfwd>
35 #include <vector>
36
37 namespace lyx {
38
39 class Buffer;
40 class BufferView;
41 class CompletionList;
42 class Cursor;
43 class CursorSlice;
44 class FuncStatus;
45 class Lexer;
46 class OutputParams;
47 class Paragraph;
48 class XHTMLStream;
49
50
51 ///
52 class InsetTableCell : public InsetText
53 {
54 public:
55         ///
56         InsetTableCell(Buffer * buf);
57         ///
58         InsetCode lyxCode() const { return CELL_CODE; }
59         ///
60         Inset * clone() const { return new InsetTableCell(*this); }
61         ///
62         bool getStatus(Cursor & cur, FuncRequest const & cmd,
63                 FuncStatus & status) const;
64         ///
65         void toggleFixedWidth(bool fw) { isFixedWidth = fw; }
66         ///
67         void setContentAlignment(LyXAlignment al) {contentAlign = al; }
68         /// writes the contents of the cell as a string, optionally
69         /// descending into insets
70         docstring asString(bool intoInsets = true);
71         ///
72         docstring xhtml(XHTMLStream &, OutputParams const &) const;
73         ///
74         void addToToc(DocIterator const & di, bool output_active) const;
75 private:
76         /// unimplemented
77         InsetTableCell();
78         /// unimplemented
79         void operator=(InsetTableCell const &);
80         // FIXME
81         // This boolean is supposed to track whether the cell has had its
82         // width explicitly set. We need to know this to determine whether
83         // layout changes and paragraph customization are allowed---that is,
84         // we need it in forcePlainLayout() and allowParagraphCustomization().
85         // Unfortunately, that information is not readily available in
86         // InsetTableCell. In the case of multicolumn cells, it is present
87         // in CellData, and so would be available here if CellData were to
88         // become a member of InsetTableCell. But in the other case, it isn't
89         // even available there, but is held in Tabular::ColumnData.
90         // So, the present solution uses this boolean to track the information
91         // we need to track, and tries to keep it updated. This is not ideal,
92         // but the other solutions are no better. These are:
93         // (i)  Keep a pointer in InsetTableCell to the table;
94         // (ii) Find the table by iterating over the Buffer's insets.
95         // Solution (i) raises the problem of updating the pointer when an
96         // InsetTableCell is copied, and we'd therefore need a copy constructor
97         // in InsetTabular and then in Tabular, which seems messy, given how
98         // complicated those classes are. Solution (ii) involves a lot of
99         // iterating, since this information is needed quite often, and so may
100         // be quite slow.
101         // So, well, if someone can do better, please do!
102         // --rgh
103         ///
104         bool isFixedWidth;
105         // FIXME: Here the thoughts from the comment above also apply.
106         ///
107         LyXAlignment contentAlign;
108         /// should paragraph indendation be omitted in any case?
109         bool neverIndent() const { return true; }
110         ///
111         LyXAlignment contentAlignment() const { return contentAlign; }
112         ///
113         virtual bool usePlainLayout() const { return true; }
114         ///
115         virtual bool forcePlainLayout(idx_type = 0) const;
116         ///
117         virtual bool allowParagraphCustomization(idx_type = 0) const;
118         /// Is the width forced to some value?
119         bool hasFixedWidth() const { return isFixedWidth; }
120 };
121
122
123 //
124 // A helper struct for tables
125 //
126 class Tabular {
127 public:
128         ///
129         enum Feature {
130                 ///
131                 APPEND_ROW = 0,
132                 ///
133                 APPEND_COLUMN,
134                 ///
135                 DELETE_ROW,
136                 ///
137                 DELETE_COLUMN,
138                 ///
139                 COPY_ROW,
140                 ///
141                 COPY_COLUMN,
142                 ///
143                 MOVE_COLUMN_RIGHT,
144                 ///
145                 MOVE_COLUMN_LEFT,
146                 ///
147                 MOVE_ROW_DOWN,
148                 ///
149                 MOVE_ROW_UP,
150                 ///
151                 SET_LINE_TOP,
152                 ///
153                 SET_LINE_BOTTOM,
154                 ///
155                 SET_LINE_LEFT,
156                 ///
157                 SET_LINE_RIGHT,
158                 ///FIXME: remove
159                 TOGGLE_LINE_TOP,
160                 ///FIXME: remove
161                 TOGGLE_LINE_BOTTOM,
162                 ///FIXME: remove
163                 TOGGLE_LINE_LEFT,
164                 ///FIXME: remove
165                 TOGGLE_LINE_RIGHT,
166                 ///
167                 ALIGN_LEFT,
168                 ///
169                 ALIGN_RIGHT,
170                 ///
171                 ALIGN_CENTER,
172                 ///
173                 ALIGN_BLOCK,
174                 ///
175                 ALIGN_DECIMAL,
176                 ///
177                 VALIGN_TOP,
178                 ///
179                 VALIGN_BOTTOM,
180                 ///
181                 VALIGN_MIDDLE,
182                 ///
183                 M_ALIGN_LEFT,
184                 ///
185                 M_ALIGN_RIGHT,
186                 ///
187                 M_ALIGN_CENTER,
188                 ///
189                 M_VALIGN_TOP,
190                 ///
191                 M_VALIGN_BOTTOM,
192                 ///
193                 M_VALIGN_MIDDLE,
194                 ///
195                 MULTICOLUMN,
196                 ///
197                 SET_MULTICOLUMN,
198                 ///
199                 UNSET_MULTICOLUMN,
200                 ///
201                 MULTIROW,
202                 ///
203                 SET_MULTIROW,
204                 ///
205                 UNSET_MULTIROW,
206                 ///
207                 SET_MROFFSET,
208                 ///
209                 SET_ALL_LINES,
210                 ///
211                 UNSET_ALL_LINES,
212                 ///
213                 SET_LONGTABULAR,
214                 ///
215                 UNSET_LONGTABULAR,
216                 ///
217                 SET_PWIDTH,
218                 ///
219                 SET_MPWIDTH,
220                 ///
221                 SET_ROTATE_TABULAR,
222                 ///
223                 UNSET_ROTATE_TABULAR,
224                 ///
225                 TOGGLE_ROTATE_TABULAR,
226                 ///
227                 SET_ROTATE_CELL,
228                 ///
229                 UNSET_ROTATE_CELL,
230                 ///
231                 TOGGLE_ROTATE_CELL,
232                 ///
233                 SET_USEBOX,
234                 ///
235                 SET_LTHEAD,
236                 UNSET_LTHEAD,
237                 ///
238                 SET_LTFIRSTHEAD,
239                 UNSET_LTFIRSTHEAD,
240                 ///
241                 SET_LTFOOT,
242                 UNSET_LTFOOT,
243                 ///
244                 SET_LTLASTFOOT,
245                 UNSET_LTLASTFOOT,
246                 ///
247                 SET_LTNEWPAGE,
248                 UNSET_LTNEWPAGE,
249                 ///
250                 TOGGLE_LTCAPTION,
251                 ///
252                 SET_LTCAPTION,
253                 ///
254                 UNSET_LTCAPTION,
255                 ///
256                 SET_SPECIAL_COLUMN,
257                 ///
258                 SET_SPECIAL_MULTICOLUMN,
259                 ///
260                 SET_BOOKTABS,
261                 ///
262                 UNSET_BOOKTABS,
263                 ///
264                 SET_TOP_SPACE,
265                 ///
266                 SET_BOTTOM_SPACE,
267                 ///
268                 SET_INTERLINE_SPACE,
269                 ///
270                 SET_BORDER_LINES,
271                 ///
272                 TABULAR_VALIGN_TOP,
273                 ///
274                 TABULAR_VALIGN_MIDDLE,
275                 ///
276                 TABULAR_VALIGN_BOTTOM,
277                 ///
278                 LONGTABULAR_ALIGN_LEFT,
279                 ///
280                 LONGTABULAR_ALIGN_CENTER,
281                 ///
282                 LONGTABULAR_ALIGN_RIGHT,
283                 ///
284                 SET_DECIMAL_POINT,
285                 ///
286                 SET_TABULAR_WIDTH,
287                 ///
288                 LAST_ACTION
289         };
290         ///
291         enum {
292                 ///
293                 CELL_NORMAL = 0,
294                 ///
295                 CELL_BEGIN_OF_MULTICOLUMN,
296                 ///
297                 CELL_PART_OF_MULTICOLUMN,
298                 ///
299                 CELL_BEGIN_OF_MULTIROW,
300                 ///
301                 CELL_PART_OF_MULTIROW
302         };
303
304         ///
305         enum VAlignment {
306                 ///
307                 LYX_VALIGN_TOP = 0,
308                 ///
309                 LYX_VALIGN_MIDDLE = 1,
310                 ///
311                 LYX_VALIGN_BOTTOM = 2
312
313         };
314         ///
315         enum HAlignment {
316                 ///
317                 LYX_LONGTABULAR_ALIGN_LEFT = 0,
318                 ///
319                 LYX_LONGTABULAR_ALIGN_CENTER = 1,
320                 ///
321                 LYX_LONGTABULAR_ALIGN_RIGHT = 2
322         };
323
324         enum BoxType {
325                 ///
326                 BOX_NONE = 0,
327                 ///
328                 BOX_PARBOX = 1,
329                 ///
330                 BOX_MINIPAGE = 2
331         };
332
333         enum CaptionType {
334                 ///
335                 CAPTION_FIRSTHEAD,
336                 ///
337                 CAPTION_HEAD,
338                 ///
339                 CAPTION_FOOT,
340                 ///
341                 CAPTION_LASTFOOT,
342                 ///
343                 CAPTION_ANY
344         };
345
346         enum RowDirection {
347                 UP,
348                 DOWN
349         };
350
351         enum ColDirection {
352                 RIGHT,
353                 LEFT
354         };
355
356         class ltType {
357         public:
358                 // constructor
359                 ltType();
360                 // we have this header type (is set in the getLT... functions)
361                 bool set;
362                 // double borders on top
363                 bool topDL;
364                 // double borders on bottom
365                 bool bottomDL;
366                 // used for FirstHeader & LastFooter and if this is true
367                 // all the rows marked as FirstHeader or LastFooter are
368                 // ignored in the output and it is set to be empty!
369                 bool empty;
370         };
371
372         /// type for row numbers
373         typedef size_t row_type;
374         /// type for column numbers
375         typedef size_t col_type;
376         /// type for cell indices
377         typedef size_t idx_type;
378         /// index indicating an invalid position
379         static const idx_type npos = static_cast<idx_type>(-1);
380
381         /// constructor
382         Tabular(Buffer * buf, col_type columns_arg, row_type rows_arg);
383
384         /// Returns true if there is a topline, returns false if not
385         bool topLine(idx_type cell) const;
386         /// Returns true if there is a topline, returns false if not
387         bool bottomLine(idx_type cell) const;
388         /// Returns true if there is a topline, returns false if not
389         bool leftLine(idx_type cell) const;
390         /// Returns true if there is a topline, returns false if not
391         bool rightLine(idx_type cell) const;
392
393         /// return space occupied by the second horizontal line and
394         /// interline space above row \p row in pixels
395         int interRowSpace(row_type row) const;
396         ///
397         int interColumnSpace(idx_type cell) const;
398
399         /* returns the maximum over all rows */
400         ///
401         int cellWidth(idx_type cell) const;
402         ///
403         int cellHeight(idx_type cell) const;
404         ///
405         int width() const;
406         ///
407         int height() const;
408         ///
409         row_type nrows() const {return row_info.size();}
410         ///
411         col_type ncols() const {return column_info.size();}
412         ///
413         int rowAscent(row_type row) const;
414         ///
415         int rowDescent(row_type row) const;
416         ///
417         void setRowAscent(row_type row, int height);
418         ///
419         void setRowDescent(row_type row, int height);
420         ///
421         void setTopLine(idx_type cell, bool line);
422         ///
423         void setBottomLine(idx_type cell, bool line);
424         ///
425         void setLeftLine(idx_type cell, bool line);
426         ///
427         void setRightLine(idx_type cell, bool line);
428         ///
429         bool rowTopLine(row_type row) const;
430         ///
431         bool rowBottomLine(row_type row) const;
432         ///
433         bool columnLeftLine(col_type column) const;
434         ///
435         bool columnRightLine(col_type column) const;
436
437         void setAlignment(idx_type cell, LyXAlignment align,
438                           bool onlycolumn = false);
439         ///
440         void setVAlignment(idx_type cell, VAlignment align,
441                            bool onlycolumn = false);
442         ///
443         void setTabularWidth(Length const & l) { tabular_width = l; }
444         ///
445         Length tabularWidth() const { return tabular_width; }
446         ///
447         void setColumnPWidth(Cursor &, idx_type, Length const &);
448         ///
449         bool setMColumnPWidth(Cursor &, idx_type, Length const &);
450         ///
451         bool setMROffset(Cursor &, idx_type, Length const &);
452         ///
453         void setAlignSpecial(idx_type cell, docstring const & special,
454                              Feature what);
455         ///
456         LyXAlignment getAlignment(idx_type cell,
457                                   bool onlycolumn = false) const;
458         ///
459         VAlignment getVAlignment(idx_type cell,
460                                  bool onlycolumn = false) const;
461         ///
462         Length const getPWidth(idx_type cell) const;
463         ///
464         Length const getMROffset(idx_type cell) const;
465         ///
466         int textHOffset(idx_type cell) const;
467         ///
468         int textVOffset(idx_type cell) const;
469         ///
470         void appendRow(row_type row);
471         ///
472         void deleteRow(row_type row);
473         ///
474         void copyRow(row_type row);
475         ///
476         void insertRow(row_type row, bool copy);
477         ///
478         void moveColumn(col_type col, ColDirection direction);
479         ///
480         void moveRow(row_type row, RowDirection direction);
481         ///
482         void appendColumn(col_type column);
483         ///
484         void deleteColumn(col_type column);
485         ///
486         void copyColumn(col_type column);
487         ///
488         void insertColumn(col_type column, bool copy);
489         ///
490         idx_type getFirstCellInRow(row_type row) const;
491         ///
492         idx_type getLastCellInRow(row_type row) const;
493         ///
494         idx_type numberOfCellsInRow(row_type row) const;
495         ///
496         void write(std::ostream &) const;
497         ///
498         void read(Lexer &);
499         ///
500         void latex(otexstream &, OutputParams const &) const;
501         ///
502         int docbook(odocstream & os, OutputParams const &) const;
503         ///
504         docstring xhtml(XHTMLStream & os, OutputParams const &) const;
505         ///
506         void plaintext(odocstringstream &,
507                        OutputParams const & runparams, int const depth,
508                        bool onlydata, char_type delim, size_t max_length = INT_MAX) const;
509         ///
510         bool isMultiColumn(idx_type cell) const;
511         ///
512         bool hasMultiColumn(col_type cell) const;
513         ///
514         idx_type setMultiColumn(idx_type cell, idx_type number,
515                              bool const right_border);
516         ///
517         void unsetMultiColumn(idx_type cell);
518         ///
519         bool isPartOfMultiColumn(row_type row, col_type column) const;
520         ///
521         bool isPartOfMultiRow(row_type row, col_type column) const;
522         ///
523         bool isMultiRow(idx_type cell) const;
524         ///
525         bool hasMultiRow(row_type r) const;
526         ///
527         idx_type setMultiRow(idx_type cell, idx_type number,
528                              bool const bottom_border,
529                              LyXAlignment const halign);
530         ///
531         void unsetMultiRow(idx_type cell);
532         ///
533         row_type cellRow(idx_type cell) const;
534         ///
535         col_type cellColumn(idx_type cell) const;
536         ///
537         void setRotateCell(idx_type cell, int);
538         ///
539         int getRotateCell(idx_type cell) const;
540         ///
541         bool needRotating() const;
542         ///
543         bool isLastCell(idx_type cell) const;
544         ///
545         idx_type cellAbove(idx_type cell) const;
546         ///
547         idx_type cellBelow(idx_type cell) const;
548         /// \return the index of the VISIBLE cell at row, column
549         /// this will be the same as the cell in the previous row,
550         /// e.g., if the cell is part of a multirow
551         idx_type cellIndex(row_type row, col_type column) const;
552         ///
553         void setUsebox(idx_type cell, BoxType);
554         ///
555         BoxType getUsebox(idx_type cell) const;
556         //
557         // Long Tabular Options support functions
558         ///
559         void setLTHead(row_type row, bool flag, ltType const &, bool first);
560         ///
561         bool getRowOfLTHead(row_type row, ltType &) const;
562         ///
563         bool getRowOfLTFirstHead(row_type row, ltType &) const;
564         ///
565         void setLTFoot(row_type row, bool flag, ltType const &, bool last);
566         ///
567         bool getRowOfLTFoot(row_type row, ltType &) const;
568         ///
569         bool getRowOfLTLastFoot(row_type row, ltType &) const;
570         ///
571         void setLTNewPage(row_type row, bool what);
572         ///
573         bool getLTNewPage(row_type row) const;
574         ///
575         idx_type setLTCaption(row_type row, bool what);
576         ///
577         bool ltCaption(row_type row) const;
578         ///
579         bool haveLTHead(bool withcaptions = true) const;
580         ///
581         bool haveLTFirstHead(bool withcaptions = true) const;
582         ///
583         bool haveLTFoot(bool withcaptions = true) const;
584         ///
585         bool haveLTLastFoot(bool withcaptions = true) const;
586         ///
587         bool haveLTCaption(CaptionType captiontype = CAPTION_ANY) const;
588         ///
589         // end longtable support
590
591         //@{
592         /// there is a subtle difference between these two methods.
593         ///   cellInset(r,c);
594         /// and
595         ///   cellInset(cellIndex(r,c));
596         /// can return different things. this is because cellIndex(r,c)
597         /// returns the VISIBLE cell at r,c, which may be the same as the
598         /// cell at the previous row or column, if we're dealing with some
599         /// multirow or multicell.
600         shared_ptr<InsetTableCell> cellInset(idx_type cell) const;
601         shared_ptr<InsetTableCell> cellInset(row_type row,
602                                                   col_type column) const;
603         //@}
604         ///
605         void setCellInset(row_type row, col_type column,
606                           shared_ptr<InsetTableCell>) const;
607         /// Search for \param inset in the tabular, with the
608         ///
609         void validate(LaTeXFeatures &) const;
610
611         //private:
612         // FIXME Now that cells have an InsetTableCell as their insets, rather
613         // than an InsetText, it'd be possible to reverse the relationship here,
614         // so that cell_vector was a vector<InsetTableCell> rather than a
615         // vector<CellData>, and an InsetTableCell had a CellData as a member,
616         // or perhaps just had its members as members.
617         ///
618         class CellData {
619         public:
620                 ///
621                 CellData(Buffer *);
622                 ///
623                 CellData(CellData const &);
624                 ///
625                 CellData & operator=(CellData const &);
626                 ///
627                 idx_type cellno;
628                 ///
629                 int width;
630                 ///
631                 int multicolumn;
632                 ///
633                 int multirow;
634                 ///
635                 Length mroffset;
636                 ///
637                 LyXAlignment alignment;
638                 ///
639                 VAlignment valignment;
640                 /// width of the part before the decimal
641                 int decimal_hoffset;
642                 /// width of the decimal part
643                 int decimal_width;
644                 ///
645                 int voffset;
646                 ///
647                 bool top_line;
648                 ///
649                 bool bottom_line;
650                 ///
651                 bool left_line;
652                 ///
653                 bool right_line;
654                 ///
655                 BoxType usebox;
656                 ///
657                 int rotate;
658                 ///
659                 docstring align_special;
660                 ///
661                 Length p_width; // this is only set for multicolumn!!!
662                 ///
663                 shared_ptr<InsetTableCell> inset;
664         };
665         CellData & cellInfo(idx_type cell) const;
666         ///
667         typedef std::vector<CellData> cell_vector;
668         ///
669         typedef std::vector<cell_vector> cell_vvector;
670
671         ///
672         class RowData {
673         public:
674                 ///
675                 RowData();
676                 ///
677                 int ascent;
678                 ///
679                 int descent;
680                 /// Extra space between the top line and this row
681                 Length top_space;
682                 /// Ignore top_space if true and use the default top space
683                 bool top_space_default;
684                 /// Extra space between this row and the bottom line
685                 Length bottom_space;
686                 /// Ignore bottom_space if true and use the default bottom space
687                 bool bottom_space_default;
688                 /// Extra space between the bottom line and the next top line
689                 Length interline_space;
690                 /// Ignore interline_space if true and use the default interline space
691                 bool interline_space_default;
692                 /// This are for longtabulars only
693                 /// a row of endhead
694                 bool endhead;
695                 /// a row of endfirsthead
696                 bool endfirsthead;
697                 /// a row of endfoot
698                 bool endfoot;
699                 /// row of endlastfoot
700                 bool endlastfoot;
701                 /// row for a newpage
702                 bool newpage;
703                 /// caption
704                 bool caption;
705         };
706         ///
707         typedef std::vector<RowData> row_vector;
708
709         ///
710         class ColumnData {
711                 public:
712                 ///
713                 ColumnData();
714                 ///
715                 LyXAlignment alignment;
716                 ///
717                 VAlignment valignment;
718                 ///
719                 int width;
720                 ///
721                 Length p_width;
722                 ///
723                 docstring align_special;
724                 ///
725                 docstring decimal_point;
726         };
727         ///
728         typedef std::vector<ColumnData> column_vector;
729
730         ///
731         idx_type numberofcells;
732         ///
733         std::vector<row_type> rowofcell;
734         ///
735         std::vector<col_type> columnofcell;
736         ///
737         row_vector row_info;
738         ///
739         column_vector column_info;
740         ///
741         mutable cell_vvector cell_info;
742         ///
743         Length tabular_width;
744         ///
745         bool use_booktabs;
746         ///
747         int rotate;
748         ///
749         VAlignment tabular_valignment;
750         //
751         // for long tabulars
752         ///
753         HAlignment longtabular_alignment;
754         //
755         bool is_long_tabular;
756         /// endhead data
757         ltType endhead;
758         /// endfirsthead data
759         ltType endfirsthead;
760         /// endfoot data
761         ltType endfoot;
762         /// endlastfoot data
763         ltType endlastfoot;
764
765         ///
766         void init(Buffer *, row_type rows_arg,
767                   col_type columns_arg);
768         ///
769         void updateIndexes();
770         ///
771         bool setFixedWidth(row_type r, col_type c);
772         /// return true of update is needed
773         bool updateColumnWidths();
774         ///
775         idx_type columnSpan(idx_type cell) const;
776         ///
777         idx_type rowSpan(idx_type cell) const;
778         ///
779         BoxType useParbox(idx_type cell) const;
780         ///
781         // helper function for Latex
782         ///
783         void TeXTopHLine(otexstream &, row_type row, std::string const & lang) const;
784         ///
785         void TeXBottomHLine(otexstream &, row_type row, std::string const & lang) const;
786         ///
787         void TeXCellPreamble(otexstream &, idx_type cell, bool & ismulticol, bool & ismultirow) const;
788         ///
789         void TeXCellPostamble(otexstream &, idx_type cell, bool ismulticol, bool ismultirow) const;
790         ///
791         void TeXLongtableHeaderFooter(otexstream &, OutputParams const &) const;
792         ///
793         bool isValidRow(row_type const row) const;
794         ///
795         void TeXRow(otexstream &, row_type const row,
796                     OutputParams const &) const;
797         ///
798         // helper functions for plain text
799         ///
800         bool plaintextTopHLine(odocstringstream &, row_type row,
801                                std::vector<unsigned int> const &) const;
802         ///
803         bool plaintextBottomHLine(odocstringstream &, row_type row,
804                                   std::vector<unsigned int> const &) const;
805         ///
806         void plaintextPrintCell(odocstringstream &,
807                                 OutputParams const &,
808                                 idx_type cell, row_type row, col_type column,
809                                 std::vector<unsigned int> const &,
810                                 bool onlydata, size_t max_length) const;
811         /// auxiliary function for docbook
812         int docbookRow(odocstream & os, row_type, OutputParams const &) const;
813         ///
814         docstring xhtmlRow(XHTMLStream & xs, row_type, OutputParams const &,
815                            bool header = false) const;
816
817         /// change associated Buffer
818         void setBuffer(Buffer & buffer);
819         /// retrieve associated Buffer
820         Buffer & buffer() const { return *buffer_; }
821
822 private:
823         Buffer * buffer_;
824
825 }; // Tabular
826
827
828 class InsetTabular : public Inset
829 {
830 public:
831         ///
832         InsetTabular(Buffer *, row_type rows = 1,
833                      col_type columns = 1);
834         ///
835         ~InsetTabular();
836         ///
837         void setBuffer(Buffer & buffer);
838
839         ///
840         static void string2params(std::string const &, InsetTabular &);
841         ///
842         static std::string params2string(InsetTabular const &);
843         ///
844         void read(Lexer &);
845         ///
846         void write(std::ostream &) const;
847         ///
848         void metrics(MetricsInfo &, Dimension &) const;
849         ///
850         void draw(PainterInfo & pi, int x, int y) const;
851         ///
852         void drawSelection(PainterInfo & pi, int x, int y) const;
853         ///
854         void drawBackground(PainterInfo & pi, int x, int y) const;
855         ///
856         bool editable() const { return true; }
857         ///
858         bool hasSettings() const { return true; }
859         ///
860         bool insetAllowed(InsetCode code) const;
861         ///
862         bool allowSpellCheck() const { return true; }
863         ///
864         bool canTrackChanges() const { return true; }
865         /** returns false if, when outputing LaTeX, font changes should
866             be closed before generating this inset. This is needed for
867             insets that may contain several paragraphs */
868         bool inheritFont() const { return false; }
869         ///
870         bool allowsCaptionVariation(std::string const &) const;
871         ///
872         DisplayType display() const;
873         ///
874         void latex(otexstream &, OutputParams const &) const;
875         ///
876         int plaintext(odocstringstream & ods, OutputParams const & op,
877                       size_t max_length = INT_MAX) const;
878         ///
879         int docbook(odocstream &, OutputParams const &) const;
880         ///
881         docstring xhtml(XHTMLStream &, OutputParams const &) const;
882         ///
883         void validate(LaTeXFeatures & features) const;
884         ///
885         InsetCode lyxCode() const { return TABULAR_CODE; }
886         ///
887         std::string contextMenu(BufferView const &, int, int) const;
888         ///
889         std::string contextMenuName() const;
890         /// get offset of this cursor slice relative to our upper left corner
891         void cursorPos(BufferView const & bv, CursorSlice const & sl,
892                 bool boundary, int & x, int & y) const;
893         ///
894         bool tabularFeatures(Cursor & cur, std::string const & what);
895         ///
896         void tabularFeatures(Cursor & cur, Tabular::Feature feature,
897                              std::string const & val = std::string());
898         /// number of cells
899         size_t nargs() const { return tabular.numberofcells; }
900         ///
901         shared_ptr<InsetTableCell const> cell(idx_type) const;
902         ///
903         shared_ptr<InsetTableCell> cell(idx_type);
904         ///
905         Text * getText(int) const;
906
907         /// set the change for the entire inset
908         void setChange(Change const & change);
909         /// accept the changes within the inset
910         void acceptChanges();
911         /// reject the changes within the inset
912         void rejectChanges();
913
914         // this should return true if we have a "normal" cell, otherwise false.
915         // "normal" means without width set!
916         /// should all paragraphs be output with "Standard" layout?
917         virtual bool allowParagraphCustomization(idx_type cell = 0) const;
918         ///
919         virtual bool forcePlainLayout(idx_type cell = 0) const;
920         ///
921         void addPreview(DocIterator const & inset_pos,
922                 graphics::PreviewLoader &) const;
923
924         /// lock cell with given index
925         void edit(Cursor & cur, bool front, EntryDirection entry_from);
926         /// get table row from x coordinate
927         int rowFromY(Cursor & cur, int y) const;
928         /// get table column from y coordinate
929         int columnFromX(Cursor & cur, int x) const;
930         ///
931         Inset * editXY(Cursor & cur, int x, int y);
932         /// can we go further down on mouse click?
933         bool descendable(BufferView const &) const { return true; }
934         /// Update the counters of this inset and of its contents
935         void updateBuffer(ParIterator const &, UpdateType);
936         ///
937         void addToToc(DocIterator const & di, bool output_active) const;
938
939         ///
940         bool completionSupported(Cursor const &) const;
941         ///
942         bool inlineCompletionSupported(Cursor const & cur) const;
943         ///
944         bool automaticInlineCompletion() const;
945         ///
946         bool automaticPopupCompletion() const;
947         ///
948         bool showCompletionCursor() const;
949         ///
950         CompletionList const * createCompletionList(Cursor const & cur) const;
951         ///
952         docstring completionPrefix(Cursor const & cur) const;
953         ///
954         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
955         ///
956         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
957         ///
958         virtual bool usePlainLayout() const { return true; }
959
960         ///
961         InsetTabular * asInsetTabular() { return this; }
962         ///
963         InsetTabular const * asInsetTabular() const { return this; }
964         ///
965         bool isRightToLeft(Cursor & cur) const;
966         /// writes the cells between stidx and enidx as a string, optionally
967         /// descending into the insets
968         docstring asString(idx_type stidx, idx_type enidx, bool intoInsets = true);
969
970         /// Returns whether the cell in the specified row and column is selected.
971         bool isCellSelected(Cursor & cur, row_type row, col_type col) const;
972         ///
973         void setLayoutForHiddenCells(DocumentClass const & dc);
974         //
975         // Public structures and variables
976         ///
977         mutable Tabular tabular;
978
979 private:
980         ///
981         InsetTabular(InsetTabular const &);
982         ///
983         void doDispatch(Cursor & cur, FuncRequest & cmd);
984         ///
985         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
986         ///
987         Inset * clone() const { return new InsetTabular(*this); }
988
989         ///
990         void drawCellLines(PainterInfo &, int x, int y, row_type row,
991                            idx_type cell) const;
992         ///
993         void setCursorFromCoordinates(Cursor & cur, int x, int y) const;
994
995         ///
996         void moveNextCell(Cursor & cur,
997                                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
998         ///
999         void movePrevCell(Cursor & cur,
1000                                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
1001         ///
1002         int cellXPos(idx_type cell) const;
1003         ///
1004         int cellYPos(idx_type cell) const;
1005         ///
1006         void resetPos(Cursor & cur) const;
1007         ///
1008         bool copySelection(Cursor & cur);
1009         ///
1010         bool pasteClipboard(Cursor & cur);
1011         ///
1012         void cutSelection(Cursor & cur);
1013         ///
1014         void getSelection(Cursor & cur, row_type & rs, row_type & re,
1015                           col_type & cs, col_type & ce) const;
1016         ///
1017         bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
1018
1019         /// return the "Manhattan distance" to nearest corner
1020         int dist(BufferView &, idx_type cell, int x, int y) const;
1021         /// return the cell nearest to x, y
1022         idx_type getNearestCell(BufferView &, int x, int y) const;
1023
1024         /// test the rotation state of the give cell range.
1025         bool oneCellHasRotationState(bool rotated,
1026                                 row_type row_start, row_type row_end,
1027                                 col_type col_start, col_type col_end) const;
1028         ///
1029         mutable idx_type first_visible_cell;
1030         ///
1031         mutable int scx_;
1032         /// The vertical offset of the table due to the vertical
1033         /// alignment with respect to the baseline.
1034         mutable int offset_valign_;
1035         /// true when selecting rows with the mouse
1036         bool rowselect_;
1037         /// true when selecting columns with the mouse
1038         bool colselect_;
1039 };
1040
1041 std::string const featureAsString(Tabular::Feature feature);
1042
1043 /// Split cell on decimal symbol
1044 InsetTableCell splitCell(InsetTableCell & head, docstring const & decimal_sym, bool & hassep);
1045
1046 } // namespace lyx
1047
1048 #endif // INSET_TABULAR_H