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 (int na = 0, string const & nm = string(), MathInsetTypes ot = LM_OT_SIMPLE);
49 /// The virtual base destructor
50 virtual ~MathInset() {}
53 virtual void draw(Painter &, int x, int baseline) = 0;
54 /// Write LaTeX and Lyx code
55 virtual void Write(std::ostream &, bool fragile) const = 0;
56 /// Write normalized content
57 virtual void WriteNormal(std::ostream &) const;
59 virtual MathInset * clone() const = 0;
60 /// Appends itself with macro arguments substituted
61 virtual void substitute(MathArray & array, MathMacro const & macro) const;
62 /// Compute the size of the object
63 virtual void Metrics(MathStyles st) = 0;
65 virtual int ascent() const;
67 virtual int descent() const;
69 virtual int width() const;
71 virtual int height() const;
73 virtual bool hasLimits() const;
75 virtual int limits() const;
77 virtual void limits(int);
79 string const & name() const;
81 MathInsetTypes GetType() const;
82 //Man: Avoid to use these functions if it's not strictly necessary
84 virtual void SetType(MathInsetTypes t);
86 virtual void SetName(string const & n);
88 MathStyles size() const;
90 /// Where should we go when we press the up cursor key?
91 virtual bool idxUp(int & idx, int & pos) const;
93 virtual bool idxDown(int & idx, int & pos) const;
95 virtual bool idxLeft(int & idx, int & pos) const;
97 virtual bool idxRight(int & idx, int & pos) const;
99 /// Move one physical cell up
100 virtual bool idxNext(int & idx, int & pos) const;
101 /// Move one physical cell down
102 virtual bool idxPrev(int & idx, int & pos) const;
104 /// Target pos when we enter the inset from the left by pressing "Right"
105 virtual bool idxFirst(int & idx, int & pos) const;
106 /// Target pos when we enter the inset from the left by pressing "Up"
107 virtual bool idxFirstUp(int & idx, int & pos) const;
108 /// Target pos when we enter the inset from the left by pressing "Down"
109 virtual bool idxFirstDown(int & idx, int & pos) const;
111 /// Target pos when we enter the inset from the right by pressing "Left"
112 virtual bool idxLast(int & idx, int & pos) const;
113 /// Target pos when we enter the inset from the right by pressing "Up"
114 virtual bool idxLastUp(int & idx, int & pos) const;
115 /// Target pos when we enter the inset from the right by pressing "Down"
116 virtual bool idxLastDown(int & idx, int & pos) const;
118 /// Where should we go if we press home?
119 virtual bool idxHome(int & idx, int & pos) const;
120 /// Where should we go if we press end?
121 virtual bool idxEnd(int & idx, int & pos) const;
123 /// Delete a cell and move cursor
124 // the return value indicates whether the cursor should leave the inset
125 // and/or the whole inset should be deleted
126 virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
132 MathArray & cell(int);
134 MathArray const & cell(int) const;
136 MathXArray & xcell(int);
138 MathXArray const & xcell(int) const;
140 void setData(MathArray const &, int);
153 virtual int ncols() const { return 1; }
155 virtual int nrows() const { return 1; }
157 virtual int col(int) const { return 0; }
159 virtual int row(int) const { return 0; }
161 virtual void addRow(int) {}
163 virtual void delRow(int) {}
165 virtual void addCol(int) {}
167 virtual void delCol(int) {}
170 virtual void UserSetSize(MathStyles &) {}
173 void GetXY(int & x, int & y) const;
175 bool covers(int x, int y) const;
176 /// Identifies ScriptInsets
177 virtual bool isScriptInset() const { return false; }
178 /// Identifies AccentInsets
179 virtual bool isAccentInset() const { return false; }
181 virtual bool isActive() const { return nargs() > 0; }
185 void push_back(MathInset *);
187 void push_back(byte ch, MathTextCodes fcode);
193 static int workwidth;
198 MathInsetTypes objtype;
206 void size(MathStyles s);
212 typedef std::vector<MathXArray> cells_type;
214 * The contents of the inset are contained here.
215 * Each inset is build from a number of insets.
221 /// Cursor start position in pixels from the document top
227 std::ostream & operator<<(std::ostream &, MathInset const &);