2001-06-25 00:06:33 +00:00
|
|
|
|
// -*- C++ -*-
|
|
|
|
|
#ifndef MATH_GRID_H
|
|
|
|
|
#define MATH_GRID_H
|
|
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
|
#include "math_nestinset.h"
|
2001-08-10 11:51:06 +00:00
|
|
|
|
#include "vspace.h"
|
2001-08-09 09:19:18 +00:00
|
|
|
|
#include "LString.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma interface
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/** Gridded math inset base class.
|
|
|
|
|
This is the base to all grid-like editable math objects
|
|
|
|
|
like array and eqnarray.
|
2002-09-11 08:26:02 +00:00
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz 2001
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-06-25 00:06:33 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
|
class MathGridInset : public MathNestInset {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-08-01 07:22:01 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// additional per-cell information
|
|
|
|
|
struct CellInfo {
|
|
|
|
|
///
|
|
|
|
|
CellInfo();
|
|
|
|
|
/// a dummy cell before a multicolumn cell
|
|
|
|
|
int dummy_;
|
|
|
|
|
/// special multi colums alignment
|
|
|
|
|
string align_;
|
2002-07-31 17:26:14 +00:00
|
|
|
|
/// these should be a per-cell property, but ok to have it here
|
|
|
|
|
/// for single-column grids like paragraphs
|
|
|
|
|
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
|
|
|
|
|
struct RowInfo {
|
|
|
|
|
///
|
|
|
|
|
RowInfo();
|
2001-08-10 12:12:03 +00:00
|
|
|
|
///
|
|
|
|
|
int skipPixels() const;
|
2001-08-06 17:20:26 +00:00
|
|
|
|
/// cached descent
|
|
|
|
|
mutable int descent_;
|
|
|
|
|
/// cached ascent
|
|
|
|
|
mutable int ascent_;
|
|
|
|
|
/// cached offset
|
|
|
|
|
mutable int offset_;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
/// how many hlines above this row?
|
|
|
|
|
int lines_;
|
|
|
|
|
/// parameter to the line break
|
|
|
|
|
LyXLength crskip_;
|
|
|
|
|
/// extra distance between lines
|
|
|
|
|
int skip_;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// additional per-row information
|
|
|
|
|
struct ColInfo {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
|
ColInfo();
|
2001-09-04 13:32:06 +00:00
|
|
|
|
/// currently possible: 'l', 'c', 'r'
|
|
|
|
|
char align_;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
/// cache for drawing
|
|
|
|
|
int h_offset;
|
2001-08-06 17:20:26 +00:00
|
|
|
|
/// cached width
|
|
|
|
|
mutable int width_;
|
|
|
|
|
/// cached offset
|
|
|
|
|
mutable int offset_;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
/// do we need a line to the left?
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool leftline_;
|
2001-09-04 13:32:06 +00:00
|
|
|
|
/// do we need a line to the right?
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool rightline_;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
/// how many lines to the left of this column?
|
|
|
|
|
int lines_;
|
2001-09-04 13:32:06 +00:00
|
|
|
|
/// additional amount to be skipped when drawing
|
|
|
|
|
int skip_;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
public:
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// sets nrows and ncols to 1
|
|
|
|
|
MathGridInset();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
/// constructor from columns description, creates one row
|
|
|
|
|
MathGridInset(char valign, string const & halign);
|
2001-09-26 16:52:34 +00:00
|
|
|
|
/// Note: columns first!
|
|
|
|
|
MathGridInset(col_type m, row_type n);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2001-11-12 16:45:09 +00:00
|
|
|
|
MathGridInset(col_type m, row_type n, char valign, string const & halign);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
///
|
2001-12-15 16:13:11 +00:00
|
|
|
|
MathInset * clone() const;
|
|
|
|
|
///
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void metrics(MathMetricsInfo & mi) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void draw(MathPainterInfo & pi, int x, int y) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void metricsT(TextMetricsInfo const & mi) 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;
|
2002-03-19 16:55:58 +00:00
|
|
|
|
///
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void halign(string const & align);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
|
void halign(char c, col_type col);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
|
char halign(col_type col) const;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
///
|
2001-11-28 13:09:40 +00:00
|
|
|
|
string halign() const;
|
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void valign(char c);
|
|
|
|
|
///
|
2001-06-27 14:10:35 +00:00
|
|
|
|
char valign() const;
|
|
|
|
|
///
|
2001-11-28 13:09:40 +00:00
|
|
|
|
void vcrskip(LyXLength const &, row_type row);
|
2001-08-10 11:51:06 +00:00
|
|
|
|
///
|
2001-11-28 13:09:40 +00:00
|
|
|
|
LyXLength 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]; }
|
|
|
|
|
///
|
|
|
|
|
CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
|
2001-10-12 12:02:49 +00:00
|
|
|
|
/// identifies GridInset
|
2002-08-08 16:08:11 +00:00
|
|
|
|
MathGridInset * asGridInset() { return this; }
|
|
|
|
|
/// identifies GridInset
|
|
|
|
|
MathGridInset const * asGridInset() const { return this; }
|
2002-08-13 17:43:40 +00:00
|
|
|
|
/// local dispatcher
|
|
|
|
|
result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
|
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
|
|
|
|
|
|
|
|
|
///
|
2002-07-30 13:56:02 +00:00
|
|
|
|
bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
bool idxLeft(idx_type & idx, pos_type & pos) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
bool idxRight(idx_type & idx, pos_type & pos) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
bool idxFirst(idx_type & idx, pos_type & pos) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
bool idxLast(idx_type & idx, pos_type & pos) const;
|
2001-07-09 16:59:57 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
bool idxHome(idx_type & idx, pos_type & pos) const;
|
2001-10-23 07:33:03 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
bool idxEnd(idx_type & idx, pos_type & pos) const;
|
2001-10-23 07:33:03 +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
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
virtual void addRow(row_type r);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
virtual void delRow(row_type r);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-08-21 13:47:52 +00:00
|
|
|
|
virtual void copyRow(row_type r);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
///
|
2002-08-21 13:47:52 +00:00
|
|
|
|
virtual void swapRow(row_type r);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
virtual void addCol(col_type c);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-07-26 13:13:20 +00:00
|
|
|
|
virtual void delCol(col_type c);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2002-08-21 13:47:52 +00:00
|
|
|
|
virtual void copyCol(col_type c);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
///
|
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;
|
|
|
|
|
///
|
|
|
|
|
void normalize(NormalStream &) const;
|
2001-11-07 10:21:51 +00:00
|
|
|
|
///
|
2001-11-09 18:02:20 +00:00
|
|
|
|
//void maplize(MapleStream &) const;
|
2001-11-07 18:15:24 +00:00
|
|
|
|
///
|
|
|
|
|
void mathmlize(MathMLStream &) const;
|
|
|
|
|
///
|
2001-11-09 18:02:20 +00:00
|
|
|
|
//void octavize(OctaveStream &) const;
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
protected:
|
2002-07-31 17:26:14 +00:00
|
|
|
|
/// returns x offset of cell compared to inset
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int cellXOffset(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
|
2002-08-15 17:41:24 +00:00
|
|
|
|
virtual string eolString(row_type row, bool fragile = false) const;
|
2001-08-10 10:39:56 +00:00
|
|
|
|
/// returns proper 'end of column' code for LaTeX
|
2002-08-15 18:04:01 +00:00
|
|
|
|
virtual string eocString(col_type col, col_type lastcol) const;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
/// extract number of columns from alignment string
|
|
|
|
|
col_type guessColumns(string const & halign) const;
|
2002-08-13 17:43:40 +00:00
|
|
|
|
/// splits cells and shifts right part to the next cell
|
|
|
|
|
void splitCell(idx_type &, pos_type & pos);
|
2001-08-10 10:39:56 +00:00
|
|
|
|
|
2002-07-31 17:26:14 +00:00
|
|
|
|
public:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
/// row info
|
|
|
|
|
std::vector<RowInfo> rowinfo_;
|
|
|
|
|
/// column info
|
|
|
|
|
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
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
|
char v_align_; // add approp. type
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|