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, 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"
34 Functions or LaTeX names for objects that I don't know how to draw.
36 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(std::ostream &, bool fragile);
53 inline bool GetLimits() const;
65 class MathAccentInset: public MathedInset {
68 MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
70 MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
74 MathedInset * Clone();
76 void draw(Painter &, int, int);
78 void Write(std::ostream &, bool fragile);
82 int getAccentCode() const { return code; }
99 class MathDotsInset: public MathedInset {
102 MathDotsInset(char const *, int, short st = LM_ST_TEXT);
104 MathedInset * Clone();
106 void draw(Painter &, int, int);
108 void Write(std::ostream &, bool fragile);
118 class MathSpaceInset: public MathedInset {
121 MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
123 MathedInset * Clone();
125 void draw(Painter &, int, int);
127 void Write(std::ostream &, bool fragile);
129 inline void Metrics();
131 inline void SetSpace(int sp);
133 int GetSpace() { return space; }
141 class MathBigopInset: public MathedInset {
144 MathBigopInset(char const *, int, short st = LM_ST_TEXT);
146 MathedInset * Clone();
148 void draw(Painter &, int, int);
150 void Write(std::ostream &, bool fragile);
154 inline bool GetLimits() const;
156 inline void SetLimits(bool);
165 //------- All editable insets must be derived from MathParInset.
168 class MathSqrtInset: public MathParInset {
171 MathSqrtInset(short st = LM_ST_TEXT);
173 MathedInset * Clone();
175 void draw(Painter &, int x, int baseline);
177 void Write(std::ostream &, bool fragile);
181 bool Inside(int, int);
188 /// Fraction like objects (frac, stackrel, binom)
189 class MathFracInset: public MathParInset {
192 MathFracInset(short ot = LM_OT_FRAC);
196 MathedInset * Clone();
198 void draw(Painter &, int x, int baseline);
200 void Write(std::ostream &, bool fragile);
204 /** This does the same that SetData(LyxArrayBase*) but for both
205 numerator and denominator at once.
207 void SetData(LyxArrayBase *, LyxArrayBase *);
209 void SetData(LyxArrayBase *);
211 void GetXY(int & x, int & y) const;
213 void SetFocus(int, int);
215 bool Inside(int, int);
217 LyxArrayBase * GetData();
219 bool setArgumentIdx(int i); // was bool Up/down(void);
221 int getArgumentIdx() { return int(idx); }
223 int getMaxArgumentIdx() { return 1; }
225 void SetStyle(short);
232 int w0, w1, des0, dh;
237 class MathDelimInset: public MathParInset {
240 MathDelimInset(int, int, short st = LM_ST_TEXT);
242 MathedInset * Clone();
244 void draw(Painter &, int, int);
246 void Write(std::ostream &, bool fragile);
257 /// Decorations over (below) a math object
258 class MathDecorationInset: public MathParInset {
261 MathDecorationInset(int, short st = LM_ST_TEXT);
263 MathedInset * Clone();
265 void draw(Painter &, int, int);
267 void Write(std::ostream &, bool fragile);
271 inline bool GetLimits() const;
282 // -------------------- Inline functions ---------------------
286 MathFuncInset::~MathFuncInset()
288 if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
293 bool MathFuncInset::GetLimits() const
295 return bool(lims && (GetStyle() == LM_ST_DISPLAY));
300 void MathFuncInset::Write(std::ostream & os, bool /* fragile */)
302 os << "\\" << name << ' ';
307 void MathSpaceInset::Metrics()
309 width = space ? space * 2 : 2;
310 if (space > 3) width *= 2;
311 if (space == 5) width *= 2;
313 ascent = 4; descent = 0;
318 void MathSpaceInset::SetSpace(int sp)
326 bool MathBigopInset::GetLimits() const
330 return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
339 void MathBigopInset::SetLimits(bool ls)
346 bool MathDecorationInset::GetLimits() const
348 return deco == LM_underbrace || deco == LM_overbrace;