#include "LString.h"
#include "debug.h"
-#include "array.h"
+//#include "array.h"
+class MathedArray;
class Painter;
+#ifndef byte
+#define byte unsigned char
+#endif
+
///
enum math_align {
///
class MathParInset;
-/** Abstract base class for all math objects.
- A math insets is for use of the math editor only, it isn't a
- general LyX inset. It's used to represent all the math objects.
- The formulaInset (a LyX inset) encapsulates a math inset.
- */
-class MathedInset {
- public:
- /// A math inset has a name (usually its LaTeX name), type and font-size
- MathedInset(string const & nm, short ot, short st);
- ///
- explicit
- MathedInset(MathedInset *);
- ///
- virtual ~MathedInset() {}
-
- /// Draw the object
- virtual void draw(Painter &, int x, int baseline) = 0;
-
- /// Write LaTeX and Lyx code
- virtual void Write(std::ostream &, bool fragile) = 0;
-
- /// Reproduces itself
- virtual MathedInset * Clone() = 0;
-
- /// Compute the size of the object
- virtual void Metrics() = 0;
- ///
- virtual int Ascent() const { return ascent; }
- ///
- virtual int Descent() const { return descent; }
- ///
- virtual int Width() const { return width; }
- ///
- virtual int Height() const { return ascent + descent; }
-
- ///
- virtual bool GetLimits() const { return false; }
- ///
- virtual void SetLimits(bool) {}
-
- ///
- string const & GetName() const { return name; }
- ///
- short GetType() const { return objtype; }
- ///
- short GetStyle() const { return size; }
-
- //Man: Avoid to use these functions if it's not strictly necessary
- ///
- virtual void SetType(short t) { objtype = t; }
- ///
- virtual void SetStyle(short st) { size = st; } // Metrics();
- ///
- virtual void SetName(string const & n) { name = n; }
- ///
- static int workWidth;
- protected:
- ///
- string name;
- ///
- short objtype;
- ///
- int width;
- ///
- int ascent;
- ///
- int descent;
- ///
- short size;
- /// Default metrics
- static int df_asc;
- ///
- static int df_des;
- ///
- static int df_width;
- /// In a near future maybe we use a better fonts renderer than X
- void drawStr(Painter &, short, int, int, int, string const &);
- ///
- friend class MathedCursor;
- ///
- friend void mathed_init_fonts();
-};
-
-struct MathedRowSt;
-
/// Paragraph permissions
enum MathedParFlag {
};
-/** The math paragraph base class, base to all editable math objects */
-class MathParInset: public MathedInset {
- public:
- ///
- MathParInset(short st = LM_ST_TEXT, string const & nm = string(),
- short ot = LM_OT_MIN);
- ///
- explicit
- MathParInset(MathParInset *);
- ///
- virtual ~MathParInset();
- ///
- virtual MathedInset * Clone();
-
- /// Draw the object on a drawable
- virtual void draw(Painter &, int x, int baseline);
-
- /// Write LaTeX code
- virtual void Write(std::ostream &, bool fragile);
-
- ///
- virtual void Metrics();
- ///
- virtual void UserSetSize(short);
-
- /// Data is stored in a LyXArray
- virtual void SetData(MathedArray *);
- ///
- virtual MathedArray * GetData() { return array; }
-
- /// Paragraph position
- virtual void GetXY(int &, int &) const;
- ///
- virtual void setXY(int x, int y) { xo = x; yo = y; }
- ///
- virtual void SetFocus(int, int) {}
- ///
- virtual bool Inside(int, int);
-
- // Tab stuff used by Matrix.
- ///
- virtual void SetAlign(char, string const &) {}
- ///
- virtual int GetColumns() const { return 1; }
- ///
- virtual int GetRows() const { return 1; }
- ///
- virtual bool isMatrix() const { return false; }
- // Vertical switching
- ///
- virtual bool setArgumentIdx(int i) { return (i == 0); }
- ///
- virtual bool setNextArgIdx() { return false; }
- ///
- virtual int getArgumentIdx() const { return 0; }
- ///
- virtual int getMaxArgumentIdx() const { return 0; }
- ///
- virtual void SetStyle(short);
- ///
- virtual MathedRowSt * getRowSt() const { return 0; }
- ///
- virtual void setRowSt(MathedRowSt *) {}
- ///
- virtual bool Permit(short f) const { return bool(f & flag); }
-
- protected:
- /// Paragraph data is stored here
- MathedArray * array;
- /// Cursor start position
- int xo;
- ///
- int yo;
- ///
- short flag;
-
- private:
- ///
- virtual void setFlag(MathedParFlag f) { flag |= f; }
- ///
- friend class InsetFormula;
- ///
- friend class MathedXIter;
- ///
- friend class MathedCursor;
- ///
- friend MathedArray * mathed_parse(unsigned flags = 0,
- MathedArray * a = 0,
- MathParInset ** p = 0);
-};
-
-
-/** The physical structure of a row and aditional information is stored here.
- It allows to manage the extra info independently of the paragraph data.
- Only used for multiline paragraphs.
- */
-struct MathedRowSt
-{
- ///
- typedef vector<int> Widths;
-
- ///
- explicit
- MathedRowSt(int n)
- : asc_(0), desc_(0), y_(0), widths_(n + 1, 0),
- numbered_(true), next_(0)
- {}
- /// Should be const but...
- MathedRowSt * getNext() const { return next_; }
- /// ...we couldn't use this.
- void setNext(MathedRowSt * n) { next_ = n; }
- ///
- string const & getLabel() const { return label_; }
- ///
- bool isNumbered() const { return numbered_; }
- ///
- int getBaseline() const { return y_; }
- ///
- void setBaseline(int b) { y_ = b; }
- ///
- int ascent() const { return asc_; }
- ///
- int descent() const { return desc_; }
- ///
- void ascent(int a) { asc_ = a; }
- ///
- void descent(int d) { desc_ = d; }
- ///
- int getTab(int i) const { return widths_[i]; }
- ///
- void setLabel(string const & l) { label_ = l; }
- ///
- void setNumbered(bool nf) { numbered_ = nf; }
- ///
- void setTab(int i, int t) { widths_[i] = t; }
-private:
- /// Vericals
- int asc_;
- int desc_;
- int y_;
- /// widths
- Widths widths_;
- ///
- string label_;
- ///
- bool numbered_;
- ///
- MathedRowSt * next_;
-};
-
-
-/** Multiline math paragraph base class.
- This is the base to all multiline editable math objects
- like array and eqnarray.
- */
-class MathMatrixInset: public MathParInset {
- public:
- ///
- explicit
- MathMatrixInset(int m = 1, int n = 1, short st = LM_ST_TEXT);
- ///
- explicit
- MathMatrixInset(MathMatrixInset *);
- ///
- MathedInset * Clone();
- ///
- virtual ~MathMatrixInset();
- ///
- void draw(Painter &, int, int);
- ///
- void Write(std::ostream &, bool fragile);
- ///
- void Metrics();
- ///
- void SetData(MathedArray *);
- ///
- void SetAlign(char, string const &);
- ///
- int GetColumns() const { return nc; }
- ///
- int GetRows() const { return nr; }
- ///
- virtual bool isMatrix() const { return true; }
-
- /// Use this to manage the extra information independently of paragraph
- MathedRowSt * getRowSt() const { return row; }
- ///
- void setRowSt(MathedRowSt * r) { row = r; }
-
- protected:
- /// Number of columns & rows
- int nc;
- ///
- int nr;
- /// tab sizes
- std::vector<int> ws_;
- ///
- char v_align; // add approp. type
- ///
- //std::vector<char> h_align;
- string h_align; // a vector would perhaps be more correct
- /// Vertical structure
- MathedRowSt * row;
-
-};
}
-inline
-MathedInset::MathedInset(string const & nm, short ot, short st):
- name(nm), objtype(ot), size(st)
-{
- width = ascent = descent = 0;
-}
-
-
-inline
-bool MathParInset::Inside(int x, int y)
-{
- return (x >= xo && x <= xo + width && y <= yo + descent && y >= yo - ascent);
-}
-
-
-inline
-void MathParInset::GetXY(int & x, int & y) const
-{
- x = xo; y = yo;
-}
-
-
-inline
-void MathParInset::UserSetSize(short sz)
-{
- if (sz >= 0) {
- size = sz;
- flag = flag & ~LMPF_FIXED_SIZE;
- }
-}
-
-
-inline
-void MathParInset::SetStyle(short sz)
-{
- if (Permit(LMPF_FIXED_SIZE)) {
- if (Permit(LMPF_SCRIPT))
- sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
- if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
- ++sz;
- }
- MathedInset::SetStyle(sz);
- }
-}
-
inline
bool is_eqn_type(short int type)
{