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: (c) 1996, 1997 Alejandro Aguilar Sierra
13 * Version: 0.8beta, Mathed & 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 Mathed and are not derived
29 #include "math_defs.h"
30 #include "symbol_def.h"
35 Functions or LaTeX names for objects that I don't know how to draw.
37 class MathFuncInset: public MathedInset {
40 MathFuncInset(char const * nm,
41 short ot = LM_OT_FUNC, short st = LM_ST_TEXT);
45 MathedInset * Clone();
47 void draw(Painter &, int, int);
49 void Write(ostream &);
51 void Write(string & file);
55 inline bool GetLimits() const;
67 class MathAccentInset: public MathedInset {
70 MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
72 MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
76 MathedInset * Clone();
78 void draw(Painter &, int, int);
80 void Write(ostream &);
82 void Write(string & file);
86 int getAccentCode() const { return code; }
103 class MathDotsInset: public MathedInset {
106 MathDotsInset(char const *, int, short st = LM_ST_TEXT);
108 MathedInset * Clone();
110 void draw(Painter &, int, int);
112 void Write(ostream &);
114 void Write(string & file);
124 class MathSpaceInset: public MathedInset {
127 MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
129 MathedInset * Clone();
131 void draw(Painter &, int, int);
133 void Write(ostream &);
135 void Write(string & file);
137 inline void Metrics();
139 inline void SetSpace(int sp);
141 int GetSpace() { return space; }
149 class MathBigopInset: public MathedInset {
152 MathBigopInset(char const *, int, short st = LM_ST_TEXT);
154 MathedInset * Clone();
156 void draw(Painter &, int, int);
158 void Write(ostream &);
160 void Write(string & file);
164 inline bool GetLimits() const;
166 inline void SetLimits(bool);
175 //------- All editable insets must be derived from MathParInset.
178 class MathSqrtInset: public MathParInset {
181 MathSqrtInset(short st = LM_ST_TEXT);
183 MathedInset * Clone();
185 void draw(Painter &, int x, int baseline);
187 void Write(ostream &);
189 void Write(string & file);
193 bool Inside(int, int);
200 /// Fraction like objects (frac, stackrel, binom)
201 class MathFracInset: public MathParInset {
204 MathFracInset(short ot = LM_OT_FRAC);
208 MathedInset * Clone();
210 void draw(Painter &, int x, int baseline);
212 void Write(ostream &);
214 void Write(string & file);
218 /** This does the same that SetData(LyxArrayBase*) but for both
219 numerator and denominator at once.
221 void SetData(LyxArrayBase *, LyxArrayBase *);
223 void SetData(LyxArrayBase *);
225 void GetXY(int & x, int & y) const;
227 void SetFocus(int, int);
229 bool Inside(int, int);
231 LyxArrayBase * GetData();
233 bool setArgumentIdx(int i); // was bool Up/down(void);
235 int getArgumentIdx() { return int(idx); }
237 int getMaxArgumentIdx() { return 1; }
239 void SetStyle(short);
246 int w0, w1, des0, dh;
251 class MathDelimInset: public MathParInset {
254 MathDelimInset(int, int, short st = LM_ST_TEXT);
256 MathedInset * Clone();
258 void draw(Painter &, int, int);
260 void Write(ostream &);
262 void Write(string & file);
273 /// Decorations over (below) a math object
274 class MathDecorationInset: public MathParInset {
277 MathDecorationInset(int, short st = LM_ST_TEXT);
279 MathedInset * Clone();
281 void draw(Painter &, int, int);
283 void Write(ostream &);
285 void Write(string & file);
289 inline bool GetLimits() const;
300 // -------------------- Inline functions ---------------------
304 MathFuncInset::~MathFuncInset()
306 if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
311 bool MathFuncInset::GetLimits() const
313 return bool(lims && (GetStyle() == LM_ST_DISPLAY));
318 void MathFuncInset::Write(ostream & os)
325 void MathFuncInset::Write(string & file)
334 void MathSpaceInset::Metrics()
336 width = space ? space * 2 : 2;
337 if (space > 3) width *= 2;
338 if (space == 5) width *= 2;
340 ascent = 4; descent = 0;
345 void MathSpaceInset::SetSpace(int sp)
353 bool MathBigopInset::GetLimits() const
357 return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
366 void MathBigopInset::SetLimits(bool ls)
373 bool MathDecorationInset::GetLimits() const
375 return deco == LM_underbrace || deco == LM_overbrace;