4 * Purpose: Declaration of insets for mathed
5 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
6 * Created: January 1996
7 * Description: Math paragraph and objects for a WYSIWYG math editor.
9 * Dependencies: Xlib, XForms
11 * Copyright: 1996, 1997 Alejandro Aguilar Sierra
13 * Version: 0.8beta, Math & Lyx project.
15 * You are free to use and modify this code under the terms of
16 * the GNU General Public Licence version 2 or later.
19 // Note: These math insets are internal to Math and are not derived
30 #include "symbol_def.h"
33 /** Abstract base class for all math objects.
34 A math insets is for use of the math editor only, it isn't a
35 general LyX inset. It's used to represent all the math objects.
36 The formulaInset (a LyX inset) encapsulates a math inset.
42 /** A math inset has a name (usually its LaTeX name),
47 MathInset (string const & nm = string(), MathInsetTypes ot = LM_OT_SIMPLE, int na = 0);
48 /// The virtual base destructor
49 virtual ~MathInset() {}
52 virtual void draw(Painter &, int x, int baseline) = 0;
53 /// Write LaTeX and Lyx code
54 virtual void Write(std::ostream &, bool fragile) const = 0;
55 /// Write normalized content
56 virtual void WriteNormal(std::ostream &) const;
58 virtual MathInset * Clone() const = 0;
59 /// Appends itself with macro arguments substituted
60 virtual void substitute(MathArray & array, MathMacro const & macro) const;
61 /// Compute the size of the object
62 virtual void Metrics(MathStyles st) = 0;
64 virtual int ascent() const;
66 virtual int descent() const;
68 virtual int width() const;
70 virtual int height() const;
72 virtual bool hasLimits() const;
74 virtual int limits() const;
76 virtual void limits(int);
78 string const & name() const;
80 MathInsetTypes GetType() const;
81 //Man: Avoid to use these functions if it's not strictly necessary
83 virtual void SetType(MathInsetTypes t);
85 virtual void SetName(string const & n);
87 MathStyles size() const;
89 /// Where should we go when we press the up cursor key?
90 virtual bool idxUp(int & idx, int & pos) const;
92 virtual bool idxDown(int & idx, int & pos) const;
94 virtual bool idxLeft(int & idx, int & pos) const;
96 virtual bool idxRight(int & idx, int & pos) const;
98 /// Target pos when we enter the inset from the left by pressing "Right"
99 virtual bool idxFirst(int & idx, int & pos) const;
100 /// Target pos when we enter the inset from the left by pressing "Up"
101 virtual bool idxFirstUp(int & idx, int & pos) const;
102 /// Target pos when we enter the inset from the left by pressing "Down"
103 virtual bool idxFirstDown(int & idx, int & pos) const;
105 /// Target pos when we enter the inset from the right by pressing "Left"
106 virtual bool idxLast(int & idx, int & pos) const;
107 /// Target pos when we enter the inset from the right by pressing "Up"
108 virtual bool idxLastUp(int & idx, int & pos) const;
109 /// Target pos when we enter the inset from the right by pressing "Down"
110 virtual bool idxLastDown(int & idx, int & pos) const;
112 /// Where should we go if we press home?
113 virtual bool idxHome(int & idx, int & pos) const;
114 /// Where should we go if we press end?
115 virtual bool idxEnd(int & idx, int & pos) const;
117 /// Delete a cell and move cursor
118 // a return value true indicates that the whole inset should be deleted
119 virtual bool idxDelete(int idx);
125 MathArray & cell(int);
127 MathArray const & cell(int) const;
129 MathXArray & xcell(int);
131 MathXArray const & xcell(int) const;
133 void setData(MathArray const &, int);
146 virtual int ncols() const { return 1; }
148 virtual int nrows() const { return 1; }
150 virtual int col(int) const { return 0; }
152 virtual int row(int) const { return 0; }
154 virtual void addRow(int) {}
156 virtual void delRow(int) {}
158 virtual void addCol(int) {}
160 virtual void delCol(int) {}
163 virtual void UserSetSize(MathStyles &) {}
166 void GetXY(int & x, int & y) const;
168 bool covers(int x, int y) const;
169 /// Identifies ScriptInsets
170 virtual bool isScriptInset() const { return false; }
172 virtual bool isActive() const { return nargs() > 0; }
176 void push_back(MathInset *);
178 void push_back(byte ch, MathTextCodes fcode);
184 static int workwidth;
189 MathInsetTypes objtype;
197 void size(MathStyles s);
203 typedef std::vector<MathXArray> cells_type;
205 * The contents of the inset are contained here.
206 * Each inset is build from a number of insets.
212 /// Cursor start position in pixels from the document top
218 std::ostream & operator<<(std::ostream &, MathInset const &);