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 {
39 MathFuncInset(char const * nm,
40 short ot = LM_OT_FUNC, short st = LM_ST_TEXT);
44 MathedInset * Clone();
46 void draw(Painter &, int, int);
48 void Write(std::ostream &);
52 inline bool GetLimits() const;
64 class MathAccentInset: public MathedInset {
67 MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
69 MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
73 MathedInset * Clone();
75 void draw(Painter &, int, int);
77 void Write(std::ostream &);
81 int getAccentCode() const { return code; }
98 class MathDotsInset: public MathedInset {
101 MathDotsInset(char const *, int, short st = LM_ST_TEXT);
103 MathedInset * Clone();
105 void draw(Painter &, int, int);
107 void Write(std::ostream &);
117 class MathSpaceInset: public MathedInset {
120 MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
122 MathedInset * Clone();
124 void draw(Painter &, int, int);
126 void Write(std::ostream &);
128 inline void Metrics();
130 inline void SetSpace(int sp);
132 int GetSpace() { return space; }
140 class MathBigopInset: public MathedInset {
143 MathBigopInset(char const *, int, short st = LM_ST_TEXT);
145 MathedInset * Clone();
147 void draw(Painter &, int, int);
149 void Write(std::ostream &);
153 inline bool GetLimits() const;
155 inline void SetLimits(bool);
164 //------- All editable insets must be derived from MathParInset.
167 class MathSqrtInset: public MathParInset {
170 MathSqrtInset(short st = LM_ST_TEXT);
172 MathedInset * Clone();
174 void draw(Painter &, int x, int baseline);
176 void Write(std::ostream &);
180 bool Inside(int, int);
187 /// Fraction like objects (frac, stackrel, binom)
188 class MathFracInset: public MathParInset {
191 MathFracInset(short ot = LM_OT_FRAC);
195 MathedInset * Clone();
197 void draw(Painter &, int x, int baseline);
199 void Write(std::ostream &);
203 /** This does the same that SetData(LyxArrayBase*) but for both
204 numerator and denominator at once.
206 void SetData(LyxArrayBase *, LyxArrayBase *);
208 void SetData(LyxArrayBase *);
210 void GetXY(int & x, int & y) const;
212 void SetFocus(int, int);
214 bool Inside(int, int);
216 LyxArrayBase * GetData();
218 bool setArgumentIdx(int i); // was bool Up/down(void);
220 int getArgumentIdx() { return int(idx); }
222 int getMaxArgumentIdx() { return 1; }
224 void SetStyle(short);
231 int w0, w1, des0, dh;
236 class MathDelimInset: public MathParInset {
239 MathDelimInset(int, int, short st = LM_ST_TEXT);
241 MathedInset * Clone();
243 void draw(Painter &, int, int);
245 void Write(std::ostream &);
256 /// Decorations over (below) a math object
257 class MathDecorationInset: public MathParInset {
260 MathDecorationInset(int, short st = LM_ST_TEXT);
262 MathedInset * Clone();
264 void draw(Painter &, int, int);
266 void Write(std::ostream &);
270 inline bool GetLimits() const;
281 // -------------------- Inline functions ---------------------
285 MathFuncInset::~MathFuncInset()
287 if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
292 bool MathFuncInset::GetLimits() const
294 return bool(lims && (GetStyle() == LM_ST_DISPLAY));
299 void MathFuncInset::Write(std::ostream & os)
301 os << "\\" << name << ' ';
306 void MathSpaceInset::Metrics()
308 width = space ? space * 2 : 2;
309 if (space > 3) width *= 2;
310 if (space == 5) width *= 2;
312 ascent = 4; descent = 0;
317 void MathSpaceInset::SetSpace(int sp)
325 bool MathBigopInset::GetLimits() const
329 return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
338 void MathBigopInset::SetLimits(bool ls)
345 bool MathDecorationInset::GetLimits() const
347 return deco == LM_underbrace || deco == LM_overbrace;