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"
|
2007-04-28 12:58:49 +00:00
|
|
|
#include "Length.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
/// additional per-cell information
|
2005-01-19 15:03:31 +00:00
|
|
|
class CellInfo {
|
|
|
|
public:
|
2003-05-02 07:52:15 +00:00
|
|
|
///
|
|
|
|
CellInfo();
|
|
|
|
/// a dummy cell before a multicolumn cell
|
|
|
|
int dummy_;
|
|
|
|
/// special multi colums alignment
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring align_;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// these should be a per-cell property, but ok to have it here
|
|
|
|
/// for single-column grids like paragraphs
|
2002-07-31 17:26:14 +00:00
|
|
|
mutable int glue_;
|
|
|
|
///
|
|
|
|
mutable pos_type begin_;
|
|
|
|
///
|
|
|
|
mutable pos_type end_;
|
2002-06-18 15:44:30 +00:00
|
|
|
};
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
/// additional per-row information
|
2005-01-19 15:03:31 +00:00
|
|
|
class RowInfo {
|
|
|
|
public:
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2003-05-02 07:52:15 +00:00
|
|
|
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
|
|
|
|
mutable int descent_;
|
|
|
|
/// cached ascent
|
|
|
|
mutable int ascent_;
|
|
|
|
/// cached offset
|
|
|
|
mutable int offset_;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// how many hlines above this row?
|
2005-02-14 14:25:18 +00:00
|
|
|
unsigned int lines_;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// parameter to the line break
|
2007-04-28 12:58:49 +00:00
|
|
|
Length crskip_;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// extra distance between lines
|
|
|
|
int skip_;
|
2007-03-19 16:08:17 +00:00
|
|
|
/// Is a page break allowed after this row?
|
2007-11-23 02:10:00 +00:00
|
|
|
bool allow_newpage_;
|
2001-06-25 00:06:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// additional per-row information
|
2005-01-19 15:03:31 +00:00
|
|
|
class ColInfo {
|
|
|
|
public:
|
2002-03-21 17:42:56 +00:00
|
|
|
///
|
2003-05-02 07:52:15 +00:00
|
|
|
ColInfo();
|
|
|
|
/// currently possible: 'l', 'c', 'r'
|
|
|
|
char align_;
|
2001-06-25 00:06:33 +00:00
|
|
|
/// cache for drawing
|
2003-05-02 07:52:15 +00:00
|
|
|
int h_offset;
|
2001-08-06 17:20:26 +00:00
|
|
|
/// cached width
|
|
|
|
mutable int width_;
|
|
|
|
/// cached offset
|
|
|
|
mutable int offset_;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// how many lines to the left of this column?
|
2005-02-14 14:25:18 +00:00
|
|
|
unsigned int lines_;
|
2003-05-02 07:52:15 +00:00
|
|
|
/// additional amount to be skipped when drawing
|
|
|
|
int skip_;
|
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_.
|
|
|
|
docstring special_;
|
2001-06-25 00:06:33 +00:00
|
|
|
};
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
public:
|
2008-03-15 08:43:16 +00:00
|
|
|
/// sets nrows and ncols to 1, vertical alingment to 'c'
|
2009-11-08 11:45:46 +00:00
|
|
|
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
|
|
|
///
|
2007-09-21 20:39:47 +00:00
|
|
|
void metrics(MetricsInfo & mi, Dimension &) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2003-03-21 14:20:48 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2005-04-26 11:12:20 +00:00
|
|
|
void drawWithMargin(PainterInfo & pi, int x, int y,
|
2005-04-04 07:13:37 +00:00
|
|
|
int lmargin = 0, int rmargin = 0) const;
|
2007-01-20 00:55:24 +00:00
|
|
|
/// draw decorations.
|
|
|
|
void drawDecoration(PainterInfo & pi, int x, int y) const
|
|
|
|
{ drawMarkers2(pi, x, y); }
|
2005-04-04 07:13:37 +00:00
|
|
|
///
|
2003-05-28 13:22:36 +00:00
|
|
|
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
|
2002-03-19 16:55:58 +00:00
|
|
|
///
|
2002-07-30 13:56:02 +00:00
|
|
|
void drawT(TextPainter & pi, int x, int y) const;
|
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
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid * asGridInset() { return this; }
|
2002-08-08 16:08:11 +00:00
|
|
|
/// identifies GridInset
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid const * asGridInset() const { return this; }
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-11-28 13:09:40 +00:00
|
|
|
col_type ncols() const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-11-28 13:09:40 +00:00
|
|
|
row_type nrows() const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-11-28 13:09:40 +00:00
|
|
|
col_type col(idx_type idx) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-11-28 13:09:40 +00:00
|
|
|
row_type row(idx_type idx) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxUpDown(Cursor &, bool up) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2007-11-05 19:44:03 +00:00
|
|
|
bool idxBackward(Cursor &) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2007-11-05 19:44:03 +00:00
|
|
|
bool idxForward(Cursor &) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxFirst(Cursor &) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxLast(Cursor &) const;
|
2001-07-09 16:59:57 +00:00
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
bool idxDelete(idx_type & idx);
|
2002-03-25 12:11:25 +00:00
|
|
|
/// pulls cell after pressing erase
|
|
|
|
void idxGlue(idx_type idx);
|
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
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
virtual void appendRow();
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
idx_type index(row_type r, col_type c) const;
|
2001-07-16 15:53:25 +00:00
|
|
|
///
|
2002-08-02 13:35:05 +00:00
|
|
|
bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
|
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();
|
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;
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
///
|
|
|
|
void write(WriteStream & os) const;
|
|
|
|
///
|
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;
|
|
|
|
///
|
2001-11-09 08:35:57 +00:00
|
|
|
void normalize(NormalStream &) const;
|
2001-11-07 10:21:51 +00:00
|
|
|
///
|
2003-02-14 14:30:09 +00:00
|
|
|
//void maple(MapleStream &) const;
|
2001-11-07 18:15:24 +00:00
|
|
|
///
|
2009-12-31 15:46:39 +00:00
|
|
|
void mathmlize(MathStream &) const;
|
2001-11-07 18:15:24 +00:00
|
|
|
///
|
2003-02-14 14:30:09 +00:00
|
|
|
//void octave(OctaveStream &) const;
|
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
|
|
|
///
|
|
|
|
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
2004-04-05 16:31:52 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
bool getStatus(Cursor & cur, FuncRequest const & cmd,
|
2004-04-05 16:31:52 +00:00
|
|
|
FuncStatus & flag) const;
|
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
|
2002-07-30 13:56:02 +00:00
|
|
|
int cellYOffset(idx_type idx) const;
|
2001-08-10 10:39:56 +00:00
|
|
|
/// returns proper 'end of line' code for LaTeX
|
2009-07-26 20:25:11 +00:00
|
|
|
virtual docstring eolString(row_type row, bool fragile) 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);
|
2001-08-10 10:39:56 +00:00
|
|
|
|
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_;
|
2009-07-16 19:00:24 +00:00
|
|
|
///
|
|
|
|
InsetCode lyxCode() const { return MATH_GRID_CODE; }
|
|
|
|
|
2008-03-15 08:43:16 +00:00
|
|
|
private:
|
2002-03-21 17:42:56 +00:00
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
char v_align_; // add approp. type
|
2008-03-15 08:43:16 +00:00
|
|
|
///
|
|
|
|
Inset * clone() const;
|
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
|