2001-06-25 00:06:33 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
* \file InsetMathGrid.h
|
2003-08-19 13:00:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#ifndef MATH_GRID_H
|
|
|
|
#define MATH_GRID_H
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathNest.h"
|
2020-08-03 12:15:09 +00:00
|
|
|
|
|
|
|
#include "support/Length.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2019-07-14 19:04:45 +00:00
|
|
|
#include <map>
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2019-07-14 19:04:45 +00:00
|
|
|
class BufferView;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
/** Gridded math inset base class.
|
2003-08-19 13:00:56 +00:00
|
|
|
* This is the base to all grid-like editable math objects
|
|
|
|
*/
|
2006-09-16 18:11:38 +00:00
|
|
|
class InsetMathGrid : public InsetMathNest {
|
2002-08-01 07:22:01 +00:00
|
|
|
public:
|
|
|
|
|
2015-05-17 11:43:37 +00:00
|
|
|
enum Multicolumn {
|
|
|
|
/// A normal cell
|
|
|
|
CELL_NORMAL = 0,
|
|
|
|
/// A multicolumn cell. The number of columns is <tt>1 + number
|
|
|
|
/// of CELL_PART_OF_MULTICOLUMN cells</tt> that follow directly
|
|
|
|
CELL_BEGIN_OF_MULTICOLUMN = 1,
|
|
|
|
/// This is a dummy cell (part of a multicolumn cell)
|
|
|
|
CELL_PART_OF_MULTICOLUMN = 2
|
|
|
|
};
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
/// additional per-cell information
|
2020-12-02 12:45:14 +00:00
|
|
|
struct CellInfo {
|
2015-05-17 11:43:37 +00:00
|
|
|
/// multicolumn flag
|
2020-12-02 12:45:14 +00:00
|
|
|
Multicolumn multi = CELL_NORMAL;
|
Run codespell on src/mathed
codespell -w -i 3 -S Makefile.in -L mathed,afe,tthe,ue,fro,uint,larg,alph,te,thes,alle,Claus,wit,nd,numer src/mathed/
2020-06-25 21:31:42 +00:00
|
|
|
/// special multi columns alignment
|
2019-07-14 15:18:56 +00:00
|
|
|
docstring align;
|
2002-06-18 15:44:30 +00:00
|
|
|
};
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
/// additional per-row information
|
2020-12-02 12:45:14 +00:00
|
|
|
struct RowInfo {
|
2001-08-10 12:12:03 +00:00
|
|
|
///
|
2008-09-18 13:59:35 +00:00
|
|
|
int skipPixels(MetricsInfo const & mi) const;
|
2001-08-06 17:20:26 +00:00
|
|
|
/// cached descent
|
2020-12-02 12:45:14 +00:00
|
|
|
mutable int descent = 0;
|
2001-08-06 17:20:26 +00:00
|
|
|
/// cached ascent
|
2020-12-02 12:45:14 +00:00
|
|
|
mutable int ascent = 0;
|
2019-07-14 19:04:45 +00:00
|
|
|
/// cached offset for each bufferview
|
|
|
|
mutable std::map<BufferView const *, int> offset;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// how many hlines above this row?
|
2020-12-02 12:45:14 +00:00
|
|
|
unsigned int lines = 0;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// parameter to the line break
|
2019-07-14 15:18:56 +00:00
|
|
|
Length crskip;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// extra distance between lines
|
2020-12-02 12:45:14 +00:00
|
|
|
int skip = 0;
|
2007-03-19 16:08:17 +00:00
|
|
|
/// Is a page break allowed after this row?
|
2020-12-02 12:45:14 +00:00
|
|
|
bool allow_newpage = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// additional per-row information
|
2020-12-02 12:45:14 +00:00
|
|
|
struct ColInfo {
|
2003-05-02 07:52:15 +00:00
|
|
|
/// currently possible: 'l', 'c', 'r'
|
2020-12-02 12:45:14 +00:00
|
|
|
char align = 'c';
|
2001-08-06 17:20:26 +00:00
|
|
|
/// cached width
|
2020-12-02 12:45:14 +00:00
|
|
|
mutable int width = 0;
|
2001-08-06 17:20:26 +00:00
|
|
|
/// cached offset
|
2020-12-02 12:45:14 +00:00
|
|
|
mutable int offset = 0;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// how many lines to the left of this column?
|
2020-12-02 12:45:14 +00:00
|
|
|
unsigned int lines = 0;
|
2015-05-17 11:43:37 +00:00
|
|
|
/// additional amount to the right to be skipped when drawing
|
2020-12-02 12:45:14 +00:00
|
|
|
int skip = 0;
|
2007-08-20 17:30:45 +00:00
|
|
|
/// Special alignment.
|
|
|
|
/// This does also contain align_ and lines_ if it is nonempty.
|
|
|
|
/// It needs to be in sync with align_ and lines_ because some
|
|
|
|
/// code only uses align_ and lines_.
|
2019-07-14 15:18:56 +00:00
|
|
|
docstring special;
|
2001-06-25 00:06:33 +00:00
|
|
|
};
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
public:
|
Run codespell on src/mathed
codespell -w -i 3 -S Makefile.in -L mathed,afe,tthe,ue,fro,uint,larg,alph,te,thes,alle,Claus,wit,nd,numer src/mathed/
2020-06-25 21:31:42 +00:00
|
|
|
/// sets nrows and ncols to 1, vertical alignment to 'c'
|
2019-09-15 21:56:17 +00:00
|
|
|
explicit InsetMathGrid(Buffer * buf);
|
2001-09-26 16:52:34 +00:00
|
|
|
/// Note: columns first!
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathGrid(Buffer * buf, col_type m, row_type n);
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathGrid(Buffer * buf, col_type m, row_type n, char valign,
|
|
|
|
docstring const & halign);
|
2001-10-12 12:02:49 +00:00
|
|
|
///
|
2020-12-02 15:13:32 +00:00
|
|
|
marker_type marker(BufferView const *) const override { return marker_type::MARKER2; };
|
2017-06-08 14:03:14 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void metrics(MetricsInfo & mi, Dimension &) const override;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const override;
|
2005-04-04 07:13:37 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const override;
|
2002-03-19 16:55:58 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void drawT(TextPainter & pi, int x, int y) const override;
|
2010-01-28 17:37:22 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
|
2008-03-15 08:43:16 +00:00
|
|
|
/// extract number of columns from alignment string
|
|
|
|
static col_type guessColumns(docstring const & halign);
|
|
|
|
/// accepts some LaTeX column codes: p,m,!,@,M,<,>
|
|
|
|
void setHorizontalAlignments(docstring const & align);
|
2002-03-19 16:55:58 +00:00
|
|
|
///
|
2008-03-15 08:43:16 +00:00
|
|
|
void setHorizontalAlignment(char c, col_type col);
|
2001-06-27 14:10:35 +00:00
|
|
|
///
|
2008-03-15 08:43:16 +00:00
|
|
|
char horizontalAlignment(col_type col) const;
|
2001-11-28 13:09:40 +00:00
|
|
|
///
|
2008-03-15 08:43:16 +00:00
|
|
|
docstring horizontalAlignments() const;
|
|
|
|
/// 't', 'b', or 'm'
|
|
|
|
void setVerticalAlignment(char c);
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2008-03-15 08:43:16 +00:00
|
|
|
char verticalAlignment() const;
|
2001-06-27 14:10:35 +00:00
|
|
|
///
|
2007-04-28 12:58:49 +00:00
|
|
|
void vcrskip(Length const &, row_type row);
|
2001-08-10 11:51:06 +00:00
|
|
|
///
|
2007-04-28 12:58:49 +00:00
|
|
|
Length vcrskip(row_type row) const;
|
2001-08-10 11:51:06 +00:00
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
void resize(short int type, col_type cols);
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
const RowInfo & rowinfo(row_type row) const;
|
2001-11-28 13:09:40 +00:00
|
|
|
/// returns topmost row if passed (-1)
|
2001-09-26 16:52:34 +00:00
|
|
|
RowInfo & rowinfo(row_type row);
|
2002-06-18 15:44:30 +00:00
|
|
|
///
|
|
|
|
const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
|
2002-12-01 22:59:25 +00:00
|
|
|
///
|
2002-06-18 15:44:30 +00:00
|
|
|
CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
|
2001-10-12 12:02:49 +00:00
|
|
|
/// identifies GridInset
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetMathGrid * asGridInset() override { return this; }
|
2002-08-08 16:08:11 +00:00
|
|
|
/// identifies GridInset
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetMathGrid const * asGridInset() const override { return this; }
|
2016-03-14 10:46:28 +00:00
|
|
|
//
|
2020-10-01 07:42:11 +00:00
|
|
|
bool isTable() const override { return true; }
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
col_type ncols() const override;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
row_type nrows() const override;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
col_type col(idx_type idx) const override;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
row_type row(idx_type idx) const override;
|
2015-05-17 11:43:37 +00:00
|
|
|
/// number of columns of cell \p idx
|
|
|
|
col_type ncellcols(idx_type idx) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool idxUpDown(Cursor &, bool up) const override;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool idxBackward(Cursor &) const override;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool idxForward(Cursor &) const override;
|
2018-04-04 16:24:14 +00:00
|
|
|
//
|
2020-10-01 07:42:11 +00:00
|
|
|
idx_type firstIdx() const override;
|
2018-04-04 16:24:14 +00:00
|
|
|
//
|
2020-10-01 07:42:11 +00:00
|
|
|
idx_type lastIdx() const override;
|
2001-07-09 16:59:57 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool idxDelete(idx_type & idx) override;
|
2002-03-25 12:11:25 +00:00
|
|
|
/// pulls cell after pressing erase
|
2020-10-01 07:42:11 +00:00
|
|
|
void idxGlue(idx_type idx) override;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2007-11-05 09:51:37 +00:00
|
|
|
/// add a row, one row down
|
2007-11-05 20:54:28 +00:00
|
|
|
virtual void addRow(row_type r);
|
2005-02-14 14:25:18 +00:00
|
|
|
/// delete a row
|
2002-07-26 13:13:20 +00:00
|
|
|
virtual void delRow(row_type r);
|
2005-02-14 14:25:18 +00:00
|
|
|
/// copy a row
|
2002-08-21 13:47:52 +00:00
|
|
|
virtual void copyRow(row_type r);
|
2005-02-14 14:25:18 +00:00
|
|
|
/// swap two rows
|
2002-08-21 13:47:52 +00:00
|
|
|
virtual void swapRow(row_type r);
|
2007-11-05 09:51:37 +00:00
|
|
|
/// add a column, here
|
2002-07-26 13:13:20 +00:00
|
|
|
virtual void addCol(col_type c);
|
2005-02-14 14:25:18 +00:00
|
|
|
/// delete a column
|
2002-07-26 13:13:20 +00:00
|
|
|
virtual void delCol(col_type c);
|
2005-02-14 14:25:18 +00:00
|
|
|
/// copy a column
|
2002-08-21 13:47:52 +00:00
|
|
|
virtual void copyCol(col_type c);
|
2005-02-14 14:25:18 +00:00
|
|
|
/// swap two columns
|
2002-08-21 13:47:52 +00:00
|
|
|
virtual void swapCol(col_type c);
|
2002-06-03 07:31:08 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
idx_type index(row_type r, col_type c) const override;
|
2001-07-16 15:53:25 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool idxBetween(idx_type idx, idx_type from, idx_type to) const override;
|
2001-09-04 13:32:06 +00:00
|
|
|
///
|
2001-11-28 13:09:40 +00:00
|
|
|
virtual int defaultColSpace(col_type) { return 0; }
|
2001-09-04 13:32:06 +00:00
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
virtual char defaultColAlign(col_type) { return 'c'; }
|
2001-09-05 12:57:13 +00:00
|
|
|
///
|
|
|
|
void setDefaults();
|
2012-03-25 09:16:32 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool interpretString(Cursor & cur, docstring const & str) override;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
///
|
|
|
|
virtual int colsep() const;
|
|
|
|
///
|
|
|
|
virtual int rowsep() const;
|
|
|
|
///
|
|
|
|
virtual int hlinesep() const;
|
|
|
|
///
|
|
|
|
virtual int vlinesep() const;
|
|
|
|
///
|
|
|
|
virtual int border() const;
|
2016-11-03 22:23:11 +00:00
|
|
|
///
|
|
|
|
virtual bool handlesMulticolumn() const { return false; }
|
2002-02-11 08:19:02 +00:00
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void write(WriteStream & os) const override;
|
2001-11-09 08:35:57 +00:00
|
|
|
///
|
2008-11-16 00:18:52 +00:00
|
|
|
void write(WriteStream & os,
|
|
|
|
row_type beg_row, col_type beg_col,
|
|
|
|
row_type end_row, col_type end_col) const;
|
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void normalize(NormalStream &) const override;
|
2001-11-07 10:21:51 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
//void maple(MapleStream &) const override;
|
2001-11-07 18:15:24 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void mathmlize(MathStream &) const override;
|
2017-07-03 17:45:58 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void htmlize(HtmlStream &) const override;
|
2001-11-07 18:15:24 +00:00
|
|
|
///
|
2020-10-31 13:09:46 +00:00
|
|
|
void htmlize(HtmlStream &, std::string const & attrib) const;
|
2010-03-30 02:57:05 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void validate(LaTeXFeatures & features) const override;
|
2016-07-30 04:25:09 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
//void octave(OctaveStream &) const override;
|
2007-05-11 02:34:56 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
protected:
|
2008-03-15 08:43:16 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void doDispatch(Cursor & cur, FuncRequest & cmd) override;
|
2004-04-05 16:31:52 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
bool getStatus(Cursor & cur, FuncRequest const & cmd,
|
2020-10-01 07:42:11 +00:00
|
|
|
FuncStatus & flag) const override;
|
2002-07-31 17:26:14 +00:00
|
|
|
/// returns x offset of cell compared to inset
|
2007-09-24 13:52:04 +00:00
|
|
|
int cellXOffset(BufferView const &, idx_type idx) const;
|
2002-07-31 17:26:14 +00:00
|
|
|
/// returns y offset of cell compared to inset
|
2019-07-14 19:04:45 +00:00
|
|
|
int cellYOffset(BufferView const &, idx_type idx) const;
|
2015-05-17 11:43:37 +00:00
|
|
|
/// Width of cell, taking combined columns into account
|
|
|
|
int cellWidth(idx_type idx) const;
|
2016-09-29 18:20:33 +00:00
|
|
|
///
|
2017-01-06 08:52:10 +00:00
|
|
|
virtual int leftMargin() const { return 0; }
|
2016-09-29 18:20:33 +00:00
|
|
|
///
|
2017-01-06 08:52:10 +00:00
|
|
|
virtual int rightMargin() const { return 0; }
|
2016-09-29 18:20:33 +00:00
|
|
|
|
2001-08-10 10:39:56 +00:00
|
|
|
/// returns proper 'end of line' code for LaTeX
|
2010-11-06 02:53:29 +00:00
|
|
|
virtual docstring eolString(row_type row, bool fragile, bool latex,
|
|
|
|
bool last_eoln) const;
|
2001-08-10 10:39:56 +00:00
|
|
|
/// returns proper 'end of column' code for LaTeX
|
2006-10-22 10:15:23 +00:00
|
|
|
virtual docstring eocString(col_type col, col_type lastcol) const;
|
2002-08-13 17:43:40 +00:00
|
|
|
/// splits cells and shifts right part to the next cell
|
2007-04-26 14:56:30 +00:00
|
|
|
void splitCell(Cursor & cur);
|
2015-12-13 03:32:32 +00:00
|
|
|
/// Column alignment for display of cell \p idx.
|
2011-10-18 18:46:57 +00:00
|
|
|
/// Must not be written to file!
|
2015-05-17 11:43:37 +00:00
|
|
|
virtual char displayColAlign(idx_type idx) const;
|
2015-12-20 20:56:34 +00:00
|
|
|
/// Column spacing for display of column \p col.
|
|
|
|
/// Must not be written to file!
|
|
|
|
virtual int displayColSpace(col_type col) const;
|
|
|
|
|
|
|
|
// The following two functions are used in InsetMathHull and
|
|
|
|
// InsetMathSplit.
|
2018-10-04 14:05:46 +00:00
|
|
|
/// The value of a fixed col align for a certain hull type (can
|
|
|
|
/// depend on the "indent math" setting).
|
2019-10-20 18:50:23 +00:00
|
|
|
char colAlign(HullType type, col_type col) const;
|
2015-12-20 20:56:34 +00:00
|
|
|
/// The value of a fixed col spacing for a certain hull type
|
|
|
|
static int colSpace(HullType type, col_type col);
|
2001-08-10 10:39:56 +00:00
|
|
|
|
2016-09-29 18:20:33 +00:00
|
|
|
/// positions of vertical and horizontal lines
|
|
|
|
int vLineHOffset(col_type col, unsigned int line) const;
|
2019-07-14 19:04:45 +00:00
|
|
|
int hLineVOffset(BufferView const &, row_type row, unsigned int line) const;
|
2016-09-29 18:20:33 +00:00
|
|
|
|
2019-07-14 15:18:56 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetCode lyxCode() const override { return MATH_GRID_CODE; }
|
2019-07-14 15:18:56 +00:00
|
|
|
|
|
|
|
private:
|
2005-02-14 14:25:18 +00:00
|
|
|
/// row info.
|
|
|
|
/// rowinfo_[nrows()] is a dummy row used only for hlines.
|
2001-06-25 00:06:33 +00:00
|
|
|
std::vector<RowInfo> rowinfo_;
|
2005-02-14 14:25:18 +00:00
|
|
|
/// column info.
|
|
|
|
/// colinfo_[ncols()] is a dummy column used only for vlines.
|
2001-06-25 00:06:33 +00:00
|
|
|
std::vector<ColInfo> colinfo_;
|
2002-06-18 15:44:30 +00:00
|
|
|
/// cell info
|
|
|
|
std::vector<CellInfo> cellinfo_;
|
2002-03-21 17:42:56 +00:00
|
|
|
///
|
2016-09-29 18:20:33 +00:00
|
|
|
char v_align_; // FIXME: add approp. type
|
2008-03-15 08:43:16 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
Inset * clone() const override;
|
2001-06-25 00:06:33 +00:00
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
2008-03-15 08:43:16 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#endif
|