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.
25 #include "insets/insetbase.h"
29 Abstract base class for all math objects. A math insets is for use of the
30 math editor only, it isn't a general LyX inset. It's used to represent all
33 Math insets do not know there parents, a cursor position or things
34 like that. The are dumb object that are contained in other math insets
35 (MathNestInsets, in fact) thus forming a tree. The root of this tree is
36 always a MathHullInset, which provides an interface to the Outer World by
37 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
43 class MathAMSArrayInset;
50 class MathMatrixInset;
52 class MathParboxInset;
53 class MathScriptInset;
54 class MathStringInset;
56 class MathSymbolInset;
57 class MathUnknownInset;
68 class MathematicaStream;
75 class MathMacroTemplate;
81 class TextMetricsInfo;
85 class MathInset : public InsetBase {
87 /// our members behave nicely...
90 /// substitutes macro arguments if necessary
91 virtual void substitute(MathMacro const & macro);
92 /// draw selection between two positions
93 virtual void drawSelection(PainterInfo & pi,
94 idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
95 /// the ascent of the inset above the baseline
96 /// compute the size of the object for text based drawing
97 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
98 /// draw the object as text
99 virtual void drawT(TextPainter &, int x, int y) const;
101 /// Where should we go when we press the up or down cursor key?
102 virtual bool idxUpDown(idx_type & idx, pos_type & pos, bool up,
104 /// Where should we go when we press the up or down cursor key?
105 virtual bool idxUpDown2(idx_type & idx, pos_type & pos, bool up,
108 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
110 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
112 /// Move one physical cell up
113 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
114 /// Move one physical cell down
115 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
117 /// Target pos when we enter the inset from the left by pressing "Right"
118 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
119 /// Target pos when we enter the inset from the right by pressing "Left"
120 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
122 /// Where should we go if we press home?
123 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
124 /// Where should we go if we press end?
125 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
127 /// Delete a cell and move cursor
128 virtual bool idxDelete(idx_type &) { return false; }
129 /// pulls cell after pressing erase
130 virtual void idxGlue(idx_type) {}
131 // returns list of cell indices that are "between" from and to for
132 // selection purposes
133 virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
135 /// the number of nested cells this inset owns
136 virtual idx_type nargs() const;
138 /// return cell given its number
139 virtual MathArray & cell(idx_type);
140 /// return cell given its number
141 virtual MathArray const & cell(idx_type) const;
143 /// the number of columns of this inset if it is grid-like
144 virtual col_type ncols() const { return 1; }
145 /// the number of rows of this inset if it is grid-like
146 virtual row_type nrows() const { return 1; }
147 /// to which column belongs a cell with a given index?
148 virtual col_type col(idx_type) const { return 0; }
149 /// to which row belongs a cell with a given index?
150 virtual row_type row(idx_type) const { return 0; }
151 /// cell idex corresponding to row and column;
152 virtual idx_type index(row_type row, col_type col) const;
153 /// any additional x-offset when drawing a cell?
154 virtual int cellXOffset(idx_type) const { return 0; }
155 /// any additional y-offset when drawing a cell?
156 virtual int cellYOffset(idx_type) const { return 0; }
157 /// can we enter this cell?
158 virtual bool validCell(idx_type) const { return true; }
160 virtual void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
162 /// identifies certain types of insets
163 virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
164 virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
165 virtual MathArrayInset * asArrayInset() { return 0; }
166 virtual MathArrayInset const * asArrayInset() const { return 0; }
167 virtual MathCharInset const * asCharInset() const { return 0; }
168 virtual MathDelimInset * asDelimInset() { return 0; }
169 virtual MathDelimInset const * asDelimInset() const { return 0; }
170 virtual MathFracInset * asFracInset() { return 0; }
171 virtual MathFracInset const * asFracInset() const { return 0; }
172 virtual MathFontInset * asFontInset() { return 0; }
173 virtual MathFontInset const * asFontInset() const { return 0; }
174 virtual MathGridInset * asGridInset() { return 0; }
175 virtual MathGridInset const * asGridInset() const { return 0; }
176 virtual MathHullInset * asHullInset() { return 0; }
177 virtual MathHullInset const * asHullInset() const { return 0; }
178 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
179 virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
180 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
181 virtual MathNestInset * asNestInset() { return 0; }
182 virtual MathNestInset const * asNestInset() const { return 0; }
183 virtual MathParboxInset * asParboxInset() { return 0; }
184 virtual MathScriptInset * asScriptInset() { return 0; }
185 virtual MathScriptInset const * asScriptInset() const { return 0; }
186 virtual MathSpaceInset * asSpaceInset() { return 0; }
187 virtual MathSpaceInset const * asSpaceInset() const { return 0; }
188 virtual MathStringInset * asStringInset() { return 0; }
189 virtual MathStringInset const * asStringInset() const { return 0; }
190 virtual MathSymbolInset const * asSymbolInset() const { return 0; }
191 virtual MathUnknownInset * asUnknownInset() { return 0; }
192 virtual MathUnknownInset const * asUnknownInset() const { return 0; }
193 virtual RefInset * asRefInset() { return 0; }
195 /// identifies things that can get scripts
196 virtual bool isScriptable() const { return false; }
197 /// thing that can be moved into
198 virtual bool isActive() const { return nargs() > 0; }
199 /// is the a relational operator (used for splitting equations)
200 virtual bool isRelOp() const { return false; }
201 /// -1: text mode, 1: math mode, 0 undecided
202 enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
204 virtual mode_type currentMode() const { return UNDECIDED_MODE; }
205 /// will this get written as a single block in {..}
206 virtual bool extraBraces() const { return false; }
208 /// return the content as char if the inset is able to do so
209 virtual char getChar() const { return 0; }
210 /// identifies things that can get \limits or \nolimits
211 virtual bool takesLimits() const { return false; }
213 /// char char code if possible
214 virtual void handleFont(string const &) {}
215 /// is this inset equal to a given other inset?
216 virtual bool match(MathAtom const &) const { return false; }
217 /// replace things by other things
218 virtual void replace(ReplaceData &) {}
219 /// do we contain a given subsequence?
220 virtual bool contains(MathArray const &) const { return false; }
221 /// access to the lock (only nest array have one)
222 virtual bool lock() const { return false; }
223 /// access to the lock (only nest array have one)
224 virtual void lock(bool) {}
225 /// get notification when the cursor leaves this inset
226 virtual void notifyCursorLeaves(idx_type) {}
228 /// write LaTeX and Lyx code
229 virtual void write(WriteStream & os) const;
230 /// write normalized content
231 virtual void normalize(NormalStream &) const;
232 /// write content as something readable by Maple
233 virtual void maple(MapleStream &) const;
234 /// write content as something readable by Maxima
235 virtual void maxima(MaximaStream &) const;
236 /// write content as something readable by Mathematica
237 virtual void mathematica(MathematicaStream &) const;
238 /// write content as something resembling MathML
239 virtual void mathmlize(MathMLStream &) const;
240 /// write content as something readable by Octave
241 virtual void octave(OctaveStream &) const;
242 /// describe content if cursor inside
243 virtual void infoize(std::ostream &) const {}
244 /// describe content if cursor behind
245 virtual void infoize2(std::ostream &) const {}
246 /// plain ascii output
247 virtual int ascii(std::ostream & os, int) const;
249 virtual int linuxdoc(std::ostream & os) const;
251 virtual int docbook(std::ostream & os, bool) const;
253 /// dump content to stderr for debugging
254 virtual void dump() const;
257 virtual bool numberedType() const { return false; }
259 virtual string const & getType() const;
261 virtual void mutate(string const &) {}
262 /// how is the inset called in the .lyx file?
263 virtual string fileInsetLabel() const;
264 /// usually the latex name
265 virtual string name() const;
269 BufferView * view() const;
272 std::ostream & operator<<(std::ostream &, MathAtom const &);