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();
48 void draw(Painter &, int, int);
54 void Write(ostream &);
56 void Write(string & file);
60 inline bool GetLimits() const;
72 class MathAccentInset: public MathedInset {
75 MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
77 MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
81 MathedInset * Clone();
84 void draw(Painter &, int, int);
90 void Write(ostream &);
92 void Write(string & file);
96 int getAccentCode() const { return code; }
113 class MathDotsInset: public MathedInset {
116 MathDotsInset(char const *, int, short st = LM_ST_TEXT);
118 MathedInset * Clone();
121 void draw(Painter &, int, int);
127 void Write(ostream &);
129 void Write(string & file);
139 class MathSpaceInset: public MathedInset {
142 MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
144 MathedInset * Clone();
147 void draw(Painter &, int, int);
153 void Write(ostream &);
155 void Write(string & file);
157 inline void Metrics();
159 inline void SetSpace(int sp);
161 int GetSpace() { return space; }
169 class MathBigopInset: public MathedInset {
172 MathBigopInset(char const *, int, short st = LM_ST_TEXT);
174 MathedInset * Clone();
177 void draw(Painter &, int, int);
183 void Write(ostream &);
185 void Write(string & file);
189 inline bool GetLimits() const;
191 inline void SetLimits(bool);
200 //------- All editable insets must be derived from MathParInset.
203 class MathSqrtInset: public MathParInset {
206 MathSqrtInset(short st = LM_ST_TEXT);
208 MathedInset * Clone();
210 void draw(Painter &, int x, int baseline);
213 void Draw(int x, int baseline);
216 void Write(ostream &);
218 void Write(string & file);
222 bool Inside(int, int);
229 /// Fraction like objects (frac, stackrel, binom)
230 class MathFracInset: public MathParInset {
233 MathFracInset(short ot = LM_OT_FRAC);
237 MathedInset * Clone();
240 void draw(Painter &, int x, int baseline);
243 void Draw(int x, int baseline);
246 void Write(ostream &);
248 void Write(string & file);
252 /** This does the same that SetData(LyxArrayBase*) but for both
253 numerator and denominator at once.
255 void SetData(LyxArrayBase *, LyxArrayBase *);
257 void SetData(LyxArrayBase *);
259 void GetXY(int & x, int & y) const;
261 void SetFocus(int, int);
263 bool Inside(int, int);
265 LyxArrayBase * GetData();
267 bool setArgumentIdx(int i); // was bool Up/down(void);
269 int getArgumentIdx() { return int(idx); }
271 int getMaxArgumentIdx() { return 1; }
273 void SetStyle(short);
280 int w0, w1, des0, dh;
285 class MathDelimInset: public MathParInset {
288 MathDelimInset(int, int, short st = LM_ST_TEXT);
290 MathedInset * Clone();
293 void draw(Painter &, int, int);
299 void Write(ostream &);
301 void Write(string & file);
312 /// Decorations over (below) a math object
313 class MathDecorationInset: public MathParInset {
316 MathDecorationInset(int, short st = LM_ST_TEXT);
318 MathedInset * Clone();
321 void draw(Painter &, int, int);
327 void Write(ostream &);
329 void Write(string & file);
333 inline bool GetLimits() const;
344 // -------------------- Inline functions ---------------------
348 MathFuncInset::~MathFuncInset()
350 if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
355 bool MathFuncInset::GetLimits() const
357 return bool(lims && (GetStyle() == LM_ST_DISPLAY));
362 void MathFuncInset::Write(ostream & os)
369 void MathFuncInset::Write(string & file)
378 void MathSpaceInset::Metrics()
380 width = space ? space * 2 : 2;
381 if (space > 3) width *= 2;
382 if (space == 5) width *= 2;
384 ascent = 4; descent = 0;
389 void MathSpaceInset::SetSpace(int sp)
397 bool MathBigopInset::GetLimits() const
401 return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
410 void MathBigopInset::SetLimits(bool ls)
417 bool MathDecorationInset::GetLimits() const
419 return deco == LM_underbrace || deco == LM_overbrace;