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
30 #include "math_defs.h"
31 #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();
50 void Write(ostream &);
52 void Write(string & file);
56 inline bool GetLimits() const;
68 class MathAccentInset: public MathedInset {
71 MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
73 MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
77 MathedInset * Clone();
81 void Write(ostream &);
83 void Write(string & file);
87 int getAccentCode() const { return code; }
104 class MathDotsInset: public MathedInset {
107 MathDotsInset(char const *, int, short st = LM_ST_TEXT);
109 MathedInset * Clone();
113 void Write(ostream &);
115 void Write(string & file);
125 class MathSpaceInset: public MathedInset {
128 MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
130 MathedInset * Clone();
134 void Write(ostream &);
136 void Write(string & file);
138 inline void Metrics();
140 inline void SetSpace(int sp);
142 int GetSpace() { return space; }
150 class MathBigopInset: public MathedInset {
153 MathBigopInset(char const *, int, short st = LM_ST_TEXT);
155 MathedInset * Clone();
159 void Write(ostream &);
161 void Write(string & file);
165 inline bool GetLimits() const;
167 inline void SetLimits(bool);
176 //------- All editable insets must be derived from MathParInset.
179 class MathSqrtInset: public MathParInset {
182 MathSqrtInset(short st = LM_ST_TEXT);
184 MathedInset * Clone();
186 void Draw(int x, int baseline);
188 void Write(ostream &);
190 void Write(string & file);
194 bool Inside(int, int);
201 /// Fraction like objects (frac, stackrel, binom)
202 class MathFracInset: public MathParInset {
205 MathFracInset(short ot = LM_OT_FRAC);
209 MathedInset * Clone();
211 void Draw(int x, int baseline);
213 void Write(ostream &);
215 void Write(string & file);
219 /** This does the same that SetData(LyxArrayBase*) but for both
220 numerator and denominator at once.
222 void SetData(LyxArrayBase *, LyxArrayBase *);
224 void SetData(LyxArrayBase *);
226 void GetXY(int & x, int & y) const;
228 void SetFocus(int, int);
230 bool Inside(int, int);
232 LyxArrayBase * GetData();
234 bool setArgumentIdx(int i); // was bool Up/down(void);
236 int getArgumentIdx() { return int(idx); }
238 int getMaxArgumentIdx() { return 1; }
240 void SetStyle(short);
247 int w0, w1, des0, dh;
252 class MathDelimInset: public MathParInset {
255 MathDelimInset(int, int, short st = LM_ST_TEXT);
257 MathedInset * Clone();
261 void Write(ostream &);
263 void Write(string & file);
274 /// Decorations over (below) a math object
275 class MathDecorationInset: public MathParInset {
278 MathDecorationInset(int, short st = LM_ST_TEXT);
280 MathedInset * Clone();
284 void Write(ostream &);
286 void Write(string & file);
290 inline bool GetLimits() const;
301 // -------------------- Inline functions ---------------------
305 MathFuncInset::~MathFuncInset()
307 if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
312 bool MathFuncInset::GetLimits() const
314 return bool(lims && (GetStyle() == LM_ST_DISPLAY));
319 void MathFuncInset::Write(ostream & os)
326 void MathFuncInset::Write(string & file)
335 void MathSpaceInset::Metrics()
337 width = space ? space * 2 : 2;
338 if (space > 3) width *= 2;
339 if (space == 5) width *= 2;
341 ascent = 4; descent = 0;
346 void MathSpaceInset::SetSpace(int sp)
354 bool MathBigopInset::GetLimits() const
358 return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
367 void MathBigopInset::SetLimits(bool ls)
374 bool MathDecorationInset::GetLimits() const
376 return deco == LM_underbrace || deco == LM_overbrace;