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 * ====================================================== */
25 #include "insets/insettext.h"
26 #include "lyxlength.h"
32 /* The features the text class offers for tables */
104 UNSET_ROTATE_TABULAR,
137 CELL_BEGIN_OF_MULTICOLUMN,
139 CELL_PART_OF_MULTICOLUMN
147 LYX_VALIGN_BOTTOM = 1,
149 LYX_VALIGN_CENTER = 2
164 // row of the header/footer type end definition
166 // double borders on top
168 // double borders on bottom
172 typedef struct lttype ltType;
176 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
178 LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false);
181 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
183 LyXTabular & operator=(LyXTabular const &);
185 LyXTabular * clone(InsetTabular *, bool same_id = false);
187 /// Returns true if there is a topline, returns false if not
188 bool TopLine(int cell, bool onlycolumn = false) const;
189 /// Returns true if there is a topline, returns false if not
190 bool BottomLine(int cell, bool onlycolumn = false) const;
191 /// Returns true if there is a topline, returns false if not
192 bool LeftLine(int cell, bool onlycolumn = false) const;
193 /// Returns true if there is a topline, returns false if not
194 bool RightLine(int cell, bool onlycolumn = false) const;
197 bool TopAlreadyDrawed(int cell) const;
199 bool LeftAlreadyDrawed(int cell) const;
201 bool IsLastRow(int cell) const;
204 int GetAdditionalHeight(int row) const;
206 int GetAdditionalWidth(int cell) const;
208 /* returns the maximum over all rows */
210 int GetWidthOfColumn(int cell) const;
212 int GetWidthOfTabular() const;
214 int GetAscentOfRow(int row) const;
216 int GetDescentOfRow(int row) const;
218 int GetHeightOfTabular() const;
219 /// Returns true if a complete update is necessary, otherwise false
220 bool SetAscentOfRow(int row, int height);
221 /// Returns true if a complete update is necessary, otherwise false
222 bool SetDescentOfRow(int row, int height);
223 /// Returns true if a complete update is necessary, otherwise false
224 bool SetWidthOfCell(int cell, int new_width);
225 /// Returns true if a complete update is necessary, otherwise false
226 bool SetAllLines(int cell, bool line);
227 /// Returns true if a complete update is necessary, otherwise false
228 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
229 /// Returns true if a complete update is necessary, otherwise false
230 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
231 /// Returns true if a complete update is necessary, otherwise false
232 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
233 /// Returns true if a complete update is necessary, otherwise false
234 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
235 /// Returns true if a complete update is necessary, otherwise false
236 bool SetAlignment(int cell, LyXAlignment align,
237 bool onlycolumn = false);
238 /// Returns true if a complete update is necessary, otherwise false
239 bool SetVAlignment(int cell, VAlignment align,
240 bool onlycolumn = false);
242 bool SetColumnPWidth(int cell, LyXLength const & width);
244 bool SetMColumnPWidth(int cell, LyXLength const & width);
246 bool SetAlignSpecial(int cell, string const & special, Feature what);
248 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
250 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
252 LyXLength const GetPWidth(int cell) const;
254 LyXLength const GetColumnPWidth(int cell) const;
256 LyXLength const GetMColumnPWidth(int cell) const;
258 string const GetAlignSpecial(int cell, int what) const;
260 int GetWidthOfCell(int cell) const;
262 int GetBeginningOfTextInCell(int cell) const;
264 void AppendRow(int cell);
266 void DeleteRow(int row);
268 void AppendColumn(int cell);
270 void DeleteColumn(int column);
272 bool IsFirstCellInRow(int cell) const;
274 int GetFirstCellInRow(int row) const;
276 bool IsLastCellInRow(int cell) const;
278 int GetLastCellInRow(int row) const;
280 int GetNumberOfCells() const;
282 int NumberOfCellsInRow(int cell) const;
284 void Write(Buffer const *, std::ostream &) const;
286 void Read(Buffer const *, LyXLex &);
288 void OldFormatRead(LyXLex &, string const &);
290 // helper function for Latex returns number of newlines
292 int TeXTopHLine(std::ostream &, int row) const;
294 int TeXBottomHLine(std::ostream &, int row) const;
296 int TeXCellPreamble(std::ostream &, int cell) const;
298 int TeXCellPostamble(std::ostream &, int cell) const;
300 int Latex(Buffer const *, std::ostream &, bool, bool) const;
301 /// auxiliary function for docbook rows
302 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
304 int DocBook(Buffer const * buf, std::ostream & os) const;
306 // helper function for Latex returns number of newlines
308 int AsciiTopHLine(std::ostream &, int row,
309 std::vector<unsigned int> const &) const;
311 int AsciiBottomHLine(std::ostream &, int row,
312 std::vector<unsigned int> const &) const;
314 int AsciiPrintCell(Buffer const *, std::ostream &,
315 int cell, int row, int column,
316 std::vector<unsigned int> const &) const;
318 int Ascii(Buffer const *, std::ostream &) const;
320 bool IsMultiColumn(int cell, bool real = false) const;
322 void SetMultiColumn(int cell, int number);
324 int UnsetMultiColumn(int cell); // returns number of new cells
326 bool IsPartOfMultiColumn(int row, int column) const;
328 int row_of_cell(int cell) const;
330 int column_of_cell(int cell) const;
332 int right_column_of_cell(int cell) const;
334 void SetLongTabular(bool);
336 bool IsLongTabular() const;
338 void SetRotateTabular(bool);
340 bool GetRotateTabular() const;
342 void SetRotateCell(int cell, bool);
344 bool GetRotateCell(int cell) const;
346 bool NeedRotating() const;
348 bool IsLastCell(int cell) const;
350 int GetCellAbove(int cell) const;
352 int GetCellBelow(int cell) const;
354 int GetLastCellAbove(int cell) const;
356 int GetLastCellBelow(int cell) const;
358 int GetCellNumber(int row, int column) const;
360 void SetUsebox(int cell, BoxType);
362 BoxType GetUsebox(int cell) const;
364 // Long Tabular Options
366 bool checkLTType(int row, ltType const &) const;
368 void SetLTHead(ltType const &, bool first);
370 bool GetRowOfLTHead(int row, ltType &) const;
372 bool GetRowOfLTFirstHead(int row, ltType &) const;
374 void SetLTFoot(ltType const &, bool last);
376 bool GetRowOfLTFoot(int row, ltType &) const;
378 bool GetRowOfLTLastFoot(int row, ltType &) const;
380 void SetLTNewPage(int cell, bool what);
382 bool GetLTNewPage(int cell) const;
384 InsetText * GetCellInset(int cell) const;
386 InsetText * GetCellInset(int row, int column) const;
388 int rows() const { return rows_; }
390 int columns() const { return columns_;}
392 InsetTabular * owner() const { return owner_; }
394 void Validate(LaTeXFeatures &) const;
396 std::vector<string> const getLabelList() const;
398 /// recalculate the widths/heights only!
401 mutable int cur_cell;
414 LyXAlignment alignment;
416 VAlignment valignment;
430 string align_special;
432 LyXLength p_width; // this is only set for multicolumn!!!
437 typedef std::vector<cellstruct> cell_vector;
439 typedef std::vector<cell_vector> cell_vvector;
453 /// This are for longtabulars only
457 typedef std::vector<rowstruct> row_vector;
460 struct columnstruct {
464 LyXAlignment alignment;
466 VAlignment valignment;
476 string align_special;
479 typedef std::vector<columnstruct> column_vector;
482 void ReadNew(Buffer const * buf, std::istream & is,
483 LyXLex & lex, string const & l);
485 void ReadOld(Buffer const * buf, std::istream & is,
486 LyXLex & lex, string const & l);
494 std::vector<int> rowofcell;
496 std::vector<int> columnofcell;
500 column_vector column_info;
502 mutable cell_vvector cell_info;
504 int width_of_tabular;
510 bool is_long_tabular;
513 /// row of endfirsthead
517 /// row of endlastfoot
520 InsetTabular * owner_;
523 void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
525 void Reinit(bool reset_widths = true);
527 void set_row_column_number_info(bool oldformat = false);
528 /// Returns true if a complete update is necessary, otherwise false
529 bool SetWidthOfMulticolCell(int cell, int new_width);
531 void recalculateMulticolCells(int cell, int new_width);
532 /// Returns true if change
533 bool calculate_width_of_column(int column);
535 bool calculate_width_of_column_NMC(int column); // no multi cells
537 void calculate_width_of_tabular();
539 cellstruct * cellinfo_of_cell(int cell) const;
541 void delete_column(int column);
543 int cells_in_multicolumn(int cell) const;
545 BoxType UseParbox(int cell) const;