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"
36 Functions or LaTeX names for objects that I don't know how to draw.
38 class MathFuncInset: public MathedInset {
41 MathFuncInset(char const * nm,
42 short ot = LM_OT_FUNC, short st = LM_ST_TEXT);
46 MathedInset * Clone();
48 void draw(Painter &, int, int);
50 void Write(ostream &);
54 inline bool GetLimits() const;
66 class MathAccentInset: public MathedInset {
69 MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
71 MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
75 MathedInset * Clone();
77 void draw(Painter &, int, int);
79 void Write(ostream &);
83 int getAccentCode() const { return code; }
100 class MathDotsInset: public MathedInset {
103 MathDotsInset(char const *, int, short st = LM_ST_TEXT);
105 MathedInset * Clone();
107 void draw(Painter &, int, int);
109 void Write(ostream &);
119 class MathSpaceInset: public MathedInset {
122 MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
124 MathedInset * Clone();
126 void draw(Painter &, int, int);
128 void Write(ostream &);
130 inline void Metrics();
132 inline void SetSpace(int sp);
134 int GetSpace() { return space; }
142 class MathBigopInset: public MathedInset {
145 MathBigopInset(char const *, int, short st = LM_ST_TEXT);
147 MathedInset * Clone();
149 void draw(Painter &, int, int);
151 void Write(ostream &);
155 inline bool GetLimits() const;
157 inline void SetLimits(bool);
166 //------- All editable insets must be derived from MathParInset.
169 class MathSqrtInset: public MathParInset {
172 MathSqrtInset(short st = LM_ST_TEXT);
174 MathedInset * Clone();
176 void draw(Painter &, int x, int baseline);
178 void Write(ostream &);
182 bool Inside(int, int);
189 /// Fraction like objects (frac, stackrel, binom)
190 class MathFracInset: public MathParInset {
193 MathFracInset(short ot = LM_OT_FRAC);
197 MathedInset * Clone();
199 void draw(Painter &, int x, int baseline);
201 void Write(ostream &);
205 /** This does the same that SetData(LyxArrayBase*) but for both
206 numerator and denominator at once.
208 void SetData(LyxArrayBase *, LyxArrayBase *);
210 void SetData(LyxArrayBase *);
212 void GetXY(int & x, int & y) const;
214 void SetFocus(int, int);
216 bool Inside(int, int);
218 LyxArrayBase * GetData();
220 bool setArgumentIdx(int i); // was bool Up/down(void);
222 int getArgumentIdx() { return int(idx); }
224 int getMaxArgumentIdx() { return 1; }
226 void SetStyle(short);
233 int w0, w1, des0, dh;
238 class MathDelimInset: public MathParInset {
241 MathDelimInset(int, int, short st = LM_ST_TEXT);
243 MathedInset * Clone();
245 void draw(Painter &, int, int);
247 void Write(ostream &);
258 /// Decorations over (below) a math object
259 class MathDecorationInset: public MathParInset {
262 MathDecorationInset(int, short st = LM_ST_TEXT);
264 MathedInset * Clone();
266 void draw(Painter &, int, int);
268 void Write(ostream &);
272 inline bool GetLimits() const;
283 // -------------------- Inline functions ---------------------
287 MathFuncInset::~MathFuncInset()
289 if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
294 bool MathFuncInset::GetLimits() const
296 return bool(lims && (GetStyle() == LM_ST_DISPLAY));
301 void MathFuncInset::Write(ostream & os)
303 os << "\\" << name << ' ';
308 void MathSpaceInset::Metrics()
310 width = space ? space * 2 : 2;
311 if (space > 3) width *= 2;
312 if (space == 5) width *= 2;
314 ascent = 4; descent = 0;
319 void MathSpaceInset::SetSpace(int sp)
327 bool MathBigopInset::GetLimits() const
331 return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
340 void MathBigopInset::SetLimits(bool ls)
347 bool MathDecorationInset::GetLimits() const
349 return deco == LM_underbrace || deco == LM_overbrace;