2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ====================================================== */
22 #include "insets/insettext.h"
28 /* The features the text class offers for tables */
84 CELL_BEGIN_OF_MULTICOLUMN,
85 CELL_PART_OF_MULTICOLUMN
93 LYX_VALIGN_BOTTOM = 1,
100 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
103 LyXTabular(InsetTabular *, LyXTabular const &);
106 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
110 LyXTabular & operator=(LyXTabular const &);
112 LyXTabular * Clone(InsetTabular *);
114 /// Returns true if there is a topline, returns false if not
115 bool TopLine(int cell, bool onlycolumn=false) const;
116 /// Returns true if there is a topline, returns false if not
117 bool BottomLine(int cell, bool onlycolumn=false) const;
118 /// Returns true if there is a topline, returns false if not
119 bool LeftLine(int cell, bool onlycolumn=false) const;
120 /// Returns true if there is a topline, returns false if not
121 bool RightLine(int cell, bool onlycolumn=false) const;
124 bool TopAlreadyDrawed(int cell) const;
126 bool LeftAlreadyDrawed(int cell) const;
128 bool IsLastRow(int cell) const;
131 int GetAdditionalHeight(int cell) const;
133 int GetAdditionalWidth(int cell) const;
135 /* returns the maximum over all rows */
137 int GetWidthOfColumn(int cell) const;
139 int GetWidthOfTabular() const;
141 int GetAscentOfRow(int row) const;
143 int GetDescentOfRow(int row) const;
145 int GetHeightOfTabular() const;
146 /// Returns true if a complete update is necessary, otherwise false
147 bool SetAscentOfRow(int row, int height);
148 /// Returns true if a complete update is necessary, otherwise false
149 bool SetDescentOfRow(int row, int height);
150 /// Returns true if a complete update is necessary, otherwise false
151 bool SetWidthOfCell(int cell, int new_width);
152 /// Returns true if a complete update is necessary, otherwise false
153 bool SetAllLines(int cell, bool line);
154 /// Returns true if a complete update is necessary, otherwise false
155 bool SetTopLine(int cell, bool line, bool onlycolumn=false);
156 /// Returns true if a complete update is necessary, otherwise false
157 bool SetBottomLine(int cell, bool line, bool onlycolumn=false);
158 /// Returns true if a complete update is necessary, otherwise false
159 bool SetLeftLine(int cell, bool line, bool onlycolumn=false);
160 /// Returns true if a complete update is necessary, otherwise false
161 bool SetRightLine(int cell, bool line, bool onlycolumn=false);
162 /// Returns true if a complete update is necessary, otherwise false
163 bool SetAlignment(int cell, char align, bool onlycolumn = false);
164 /// Returns true if a complete update is necessary, otherwise false
165 bool SetVAlignment(int cell, char align, bool onlycolumn = false);
167 bool SetColumnPWidth(int cell, string const & width);
169 bool SetMColumnPWidth(int cell, string const & width);
171 bool SetAlignSpecial(int cell, string const & special, int what);
173 char GetAlignment(int cell, bool onlycolumn = false) const;
175 char GetVAlignment(int cell, bool onlycolumn = false) const;
177 string GetPWidth(int cell) const;
179 string GetColumnPWidth(int cell) const;
181 string GetMColumnPWidth(int cell) const;
183 string GetAlignSpecial(int cell, int what) const;
185 int GetWidthOfCell(int cell) const;
187 int GetBeginningOfTextInCell(int cell) const;
189 void AppendRow(int cell);
191 void DeleteRow(int cell);
193 void AppendColumn(int cell);
195 void DeleteColumn(int cell);
197 bool IsFirstCellInRow(int cell) const;
199 int GetFirstCellInRow(int row) const;
201 bool IsLastCellInRow(int cell) const;
203 int GetLastCellInRow(int row) const;
205 int GetNumberOfCells() const;
207 int NumberOfCellsInRow(int cell) const;
209 void Write(Buffer const *, std::ostream &) const;
211 void Read(Buffer const *, LyXLex &);
213 void OldFormatRead(LyXLex &, string const &);
215 /// helper function for Latex returns number of newlines
217 int TeXTopHLine(std::ostream &, int row) const;
218 int TeXBottomHLine(std::ostream &, int row) const;
219 int TeXCellPreamble(std::ostream &, int cell) const;
220 int TeXCellPostamble(std::ostream &, int cell) const;
222 int Latex(Buffer const *, std::ostream &, bool, bool) const;
224 int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
227 int RoffEndOfCell(std::ostream &, int cell);
230 char const * GetDocBookAlign(int cell, bool isColumn = false) const;
233 bool IsMultiColumn(int cell) const;
235 void SetMultiColumn(int cell, int number);
237 int UnsetMultiColumn(int cell); // returns number of new cells
239 bool IsPartOfMultiColumn(int row, int column) const;
241 int row_of_cell(int cell) const;
243 int column_of_cell(int cell) const;
245 int right_column_of_cell(int cell) const;
247 void SetLongTabular(int what);
249 bool IsLongTabular() const;
251 void SetRotateTabular(int what);
253 bool GetRotateTabular() const;
255 void SetRotateCell(int cell, int what);
257 bool GetRotateCell(int cell) const;
259 bool NeedRotating() const;
261 bool IsLastCell(int cell) const;
263 int GetCellAbove(int cell) const;
265 int GetCellBelow(int cell) const;
267 int GetLastCellAbove(int cell) const;
269 int GetLastCellBelow(int cell) const;
271 int GetCellNumber(int row, int column) const;
273 void SetLinebreaks(int cell, bool what);
275 bool GetLinebreaks(int cell) const;
277 /// Long Tabular Options
279 void SetLTHead(int cell, bool first);
281 bool GetRowOfLTHead(int cell, int & row) const;
283 bool GetRowOfLTFirstHead(int cell, int & row) const;
285 void SetLTFoot(int cell, bool last);
287 bool GetRowOfLTFoot(int cell, int & row) const;
289 bool GetRowOfLTLastFoot(int cell, int & row) const;
291 void SetLTNewPage(int cell, bool what);
293 bool GetLTNewPage(int cell) const;
295 InsetText * GetCellInset(int cell) const;
297 int rows() const { return rows_; }
299 int columns() const { return columns_;}
301 InsetTabular * owner() const { return owner_; }
303 void Validate(LaTeXFeatures &) const;
305 private: //////////////////////////////////////////////////////////////////
314 cellstruct(cellstruct const &);
316 cellstruct & operator=(cellstruct const &);
341 string align_special;
343 string p_width; // this is only set for multicolumn!!!
347 typedef std::vector<cellstruct> cell_vector;
348 typedef std::vector<cell_vector> cell_vvector;
357 // rowstruct & operator=(rowstruct const &);
363 /// This are for longtabulars only
366 typedef std::vector<rowstruct> row_vector;
369 struct columnstruct {
375 //columnstruct & operator=(columnstruct const &);
383 string align_special;
385 typedef std::vector<columnstruct> column_vector;
400 column_vector column_info;
402 mutable cell_vvector cell_info;
404 int width_of_tabular;
406 /// for long tabulars
408 int endhead; // row of endhead
409 int endfirsthead; // row of endfirsthead
410 int endfoot; // row of endfoot
411 int endlastfoot; // row of endlastfoot
413 InsetTabular * owner_;
416 void Init(int columns_arg, int rows_arg);
420 void set_row_column_number_info();
421 /// Returns true if a complete update is necessary, otherwise false
422 bool SetWidthOfMulticolCell(int cell, int new_width);
423 void recalculateMulticolCells(int cell, int new_width);
424 /// Returns true if change
425 bool calculate_width_of_column(int column);
426 bool calculate_width_of_column_NMC(int column); // no multi cells
428 void calculate_width_of_tabular();
431 cellstruct * cellinfo_of_cell(int cell) const;
434 void delete_column(int column);
437 int cells_in_multicolumn(int cell) const;