2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000-2001 The LyX Team.
9 * @author: Jürgen Vigna
11 * ====================================================== */
24 #include "insets/insettext.h"
30 /* The features the text class offers for tables */
102 UNSET_ROTATE_TABULAR,
135 CELL_BEGIN_OF_MULTICOLUMN,
137 CELL_PART_OF_MULTICOLUMN
145 LYX_VALIGN_BOTTOM = 1,
147 LYX_VALIGN_CENTER = 2
162 // row of the header/footer type end definition
164 // double borders on top
166 // double borders on bottom
170 typedef struct lttype ltType;
174 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
176 LyXTabular(InsetTabular *, LyXTabular const &);
179 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
181 LyXTabular & operator=(LyXTabular const &);
183 LyXTabular * clone(InsetTabular *);
185 /// Returns true if there is a topline, returns false if not
186 bool TopLine(int cell, bool onlycolumn = false) const;
187 /// Returns true if there is a topline, returns false if not
188 bool BottomLine(int cell, bool onlycolumn = false) const;
189 /// Returns true if there is a topline, returns false if not
190 bool LeftLine(int cell, bool onlycolumn = false) const;
191 /// Returns true if there is a topline, returns false if not
192 bool RightLine(int cell, bool onlycolumn = false) const;
195 bool TopAlreadyDrawed(int cell) const;
197 bool LeftAlreadyDrawed(int cell) const;
199 bool IsLastRow(int cell) const;
202 int GetAdditionalHeight(int row) const;
204 int GetAdditionalWidth(int cell) const;
206 /* returns the maximum over all rows */
208 int GetWidthOfColumn(int cell) const;
210 int GetWidthOfTabular() const;
212 int GetAscentOfRow(int row) const;
214 int GetDescentOfRow(int row) const;
216 int GetHeightOfTabular() const;
217 /// Returns true if a complete update is necessary, otherwise false
218 bool SetAscentOfRow(int row, int height);
219 /// Returns true if a complete update is necessary, otherwise false
220 bool SetDescentOfRow(int row, int height);
221 /// Returns true if a complete update is necessary, otherwise false
222 bool SetWidthOfCell(int cell, int new_width);
223 /// Returns true if a complete update is necessary, otherwise false
224 bool SetAllLines(int cell, bool line);
225 /// Returns true if a complete update is necessary, otherwise false
226 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
227 /// Returns true if a complete update is necessary, otherwise false
228 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
229 /// Returns true if a complete update is necessary, otherwise false
230 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
231 /// Returns true if a complete update is necessary, otherwise false
232 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
233 /// Returns true if a complete update is necessary, otherwise false
234 bool SetAlignment(int cell, LyXAlignment align,
235 bool onlycolumn = false);
236 /// Returns true if a complete update is necessary, otherwise false
237 bool SetVAlignment(int cell, VAlignment align,
238 bool onlycolumn = false);
240 bool SetColumnPWidth(int cell, string const & width);
242 bool SetMColumnPWidth(int cell, string const & width);
244 bool SetAlignSpecial(int cell, string const & special, Feature what);
246 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
248 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
250 string const GetPWidth(int cell) const;
252 string const GetColumnPWidth(int cell) const;
254 string const GetMColumnPWidth(int cell) const;
256 string const GetAlignSpecial(int cell, int what) const;
258 int GetWidthOfCell(int cell) const;
260 int GetBeginningOfTextInCell(int cell) const;
262 void AppendRow(int cell);
264 void DeleteRow(int row);
266 void AppendColumn(int cell);
268 void DeleteColumn(int column);
270 bool IsFirstCellInRow(int cell) const;
272 int GetFirstCellInRow(int row) const;
274 bool IsLastCellInRow(int cell) const;
276 int GetLastCellInRow(int row) const;
278 int GetNumberOfCells() const;
280 int NumberOfCellsInRow(int cell) const;
282 void Write(Buffer const *, std::ostream &) const;
284 void Read(Buffer const *, LyXLex &);
286 void OldFormatRead(LyXLex &, string const &);
288 // helper function for Latex returns number of newlines
290 int TeXTopHLine(std::ostream &, int row) const;
292 int TeXBottomHLine(std::ostream &, int row) const;
294 int TeXCellPreamble(std::ostream &, int cell) const;
296 int TeXCellPostamble(std::ostream &, int cell) const;
298 int Latex(Buffer const *, std::ostream &, bool, bool) const;
299 /// auxiliary function for docbook rows
300 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
302 int DocBook(Buffer const * buf, std::ostream & os) const;
304 // helper function for Latex returns number of newlines
306 int AsciiTopHLine(std::ostream &, int row,
307 std::vector<unsigned int> const &) const;
309 int AsciiBottomHLine(std::ostream &, int row,
310 std::vector<unsigned int> const &) const;
312 int AsciiPrintCell(Buffer const *, std::ostream &,
313 int cell, int row, int column,
314 std::vector<unsigned int> const &) const;
316 int Ascii(Buffer const *, std::ostream &) const;
318 bool IsMultiColumn(int cell, bool real = false) const;
320 void SetMultiColumn(int cell, int number);
322 int UnsetMultiColumn(int cell); // returns number of new cells
324 bool IsPartOfMultiColumn(int row, int column) const;
326 int row_of_cell(int cell) const;
328 int column_of_cell(int cell) const;
330 int right_column_of_cell(int cell) const;
332 void SetLongTabular(bool);
334 bool IsLongTabular() const;
336 void SetRotateTabular(bool);
338 bool GetRotateTabular() const;
340 void SetRotateCell(int cell, bool);
342 bool GetRotateCell(int cell) const;
344 bool NeedRotating() const;
346 bool IsLastCell(int cell) const;
348 int GetCellAbove(int cell) const;
350 int GetCellBelow(int cell) const;
352 int GetLastCellAbove(int cell) const;
354 int GetLastCellBelow(int cell) const;
356 int GetCellNumber(int row, int column) const;
358 void SetUsebox(int cell, BoxType);
360 BoxType GetUsebox(int cell) const;
362 // Long Tabular Options
364 bool checkLTType(int row, ltType const &) const;
366 void SetLTHead(ltType const &, bool first);
368 bool GetRowOfLTHead(int row, ltType &) const;
370 bool GetRowOfLTFirstHead(int row, ltType &) const;
372 void SetLTFoot(ltType const &, bool last);
374 bool GetRowOfLTFoot(int row, ltType &) const;
376 bool GetRowOfLTLastFoot(int row, ltType &) const;
378 void SetLTNewPage(int cell, bool what);
380 bool GetLTNewPage(int cell) const;
382 InsetText * GetCellInset(int cell) const;
384 InsetText * GetCellInset(int row, int column) const;
386 int rows() const { return rows_; }
388 int columns() const { return columns_;}
390 InsetTabular * owner() const { return owner_; }
392 void Validate(LaTeXFeatures &) const;
394 std::vector<string> const getLabelList() const;
396 mutable int cur_cell;
409 LyXAlignment alignment;
411 VAlignment valignment;
425 string align_special;
427 string p_width; // this is only set for multicolumn!!!
432 typedef std::vector<cellstruct> cell_vector;
434 typedef std::vector<cell_vector> cell_vvector;
448 /// This are for longtabulars only
452 typedef std::vector<rowstruct> row_vector;
455 struct columnstruct {
459 LyXAlignment alignment;
461 VAlignment valignment;
471 string align_special;
474 typedef std::vector<columnstruct> column_vector;
477 void ReadNew(Buffer const * buf, std::istream & is,
478 LyXLex & lex, string const & l);
480 void ReadOld(Buffer const * buf, std::istream & is,
481 LyXLex & lex, string const & l);
489 std::vector<int> rowofcell;
491 std::vector<int> columnofcell;
495 column_vector column_info;
497 mutable cell_vvector cell_info;
499 int width_of_tabular;
505 bool is_long_tabular;
508 /// row of endfirsthead
512 /// row of endlastfoot
515 InsetTabular * owner_;
518 void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
522 void set_row_column_number_info(bool oldformat = false);
523 /// Returns true if a complete update is necessary, otherwise false
524 bool SetWidthOfMulticolCell(int cell, int new_width);
526 void recalculateMulticolCells(int cell, int new_width);
527 /// Returns true if change
528 bool calculate_width_of_column(int column);
530 bool calculate_width_of_column_NMC(int column); // no multi cells
532 void calculate_width_of_tabular();
534 cellstruct * cellinfo_of_cell(int cell) const;
536 void delete_column(int column);
538 int cells_in_multicolumn(int cell) const;
540 BoxType UseParbox(int cell) const;