2001-06-25 00:06:33 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_gridinset.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
|
#include "math_nestinset.h"
|
2003-09-08 09:59:30 +00:00
|
|
|
|
#include "lyxlength.h"
|
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
|
|
|
|
|
*/
|
2001-08-03 17:10:22 +00:00
|
|
|
|
class MathGridInset : public MathNestInset {
|
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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string 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
|
|
|
|
///
|
|
|
|
|
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_;
|
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
|
|
|
|
|
LyXLength crskip_;
|
|
|
|
|
/// extra distance between lines
|
|
|
|
|
int skip_;
|
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_;
|
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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
MathGridInset(char valign, std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
MathGridInset(col_type m, row_type n, char valign, std::string const & halign);
|
2003-03-10 22:56:24 +00:00
|
|
|
|
/// Ensures that the dialog is closed.
|
|
|
|
|
~MathGridInset();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
///
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void metrics(MetricsInfo & mi) const;
|
|
|
|
|
///
|
|
|
|
|
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;
|
|
|
|
|
///
|
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;
|
2002-03-19 16:55:58 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void halign(std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string halign() const;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
///
|
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]; }
|
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
|
2002-08-08 16:08:11 +00:00
|
|
|
|
MathGridInset * asGridInset() { return this; }
|
|
|
|
|
/// identifies GridInset
|
|
|
|
|
MathGridInset 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
|
|
|
|
|
|
|
|
|
///
|
2004-01-26 10:13:15 +00:00
|
|
|
|
bool idxUpDown(LCursor &, bool up) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool idxLeft(LCursor &) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool idxRight(LCursor &) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool idxFirst(LCursor &) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
///
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool idxLast(LCursor &) 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
|
|
|
|
|
2005-02-14 14:25:18 +00:00
|
|
|
|
/// add a row
|
2002-07-26 13:13:20 +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);
|
2005-02-14 14:25:18 +00:00
|
|
|
|
/// add a column
|
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;
|
|
|
|
|
///
|
|
|
|
|
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
|
|
|
|
///
|
|
|
|
|
void mathmlize(MathMLStream &) const;
|
|
|
|
|
///
|
2003-02-14 14:30:09 +00:00
|
|
|
|
//void octave(OctaveStream &) const;
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
protected:
|
2004-11-24 21:58:42 +00:00
|
|
|
|
virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
///
|
|
|
|
|
bool getStatus(LCursor & cur, FuncRequest const & cmd,
|
|
|
|
|
FuncStatus & flag) const;
|
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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::string eocString(col_type col, col_type lastcol) const;
|
2003-05-02 07:52:15 +00:00
|
|
|
|
/// extract number of columns from alignment string
|
2003-10-06 15:43:21 +00:00
|
|
|
|
col_type guessColumns(std::string const & halign) const;
|
2002-08-13 17:43:40 +00:00
|
|
|
|
/// splits cells and shifts right part to the next cell
|
2004-01-16 12:36:23 +00:00
|
|
|
|
void splitCell(LCursor & cur);
|
2001-08-10 10:39:56 +00:00
|
|
|
|
|
2002-07-31 17:26:14 +00:00
|
|
|
|
public:
|
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
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
|
char v_align_; // add approp. type
|
2004-11-23 23:04:52 +00:00
|
|
|
|
private:
|
|
|
|
|
virtual std::auto_ptr<InsetBase> doClone() const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|