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