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
22 #ifndef __MATH_INSET__
23 #define __MATH_INSET__
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, short ot=LM_OT_FUNC, short st=LM_ST_TEXT);
49 void Write(FILE *file);
51 void Write(LString &file);
55 inline bool GetLimits() const;
67 class MathAccentInset: public MathedInset {
70 MathAccentInset(byte, MathedTextCodes, int, short st=LM_ST_TEXT);
72 MathAccentInset(MathedInset *, int, short st=LM_ST_TEXT);
80 void Write(FILE *file);
82 void Write(LString &file);
86 int getAccentCode() const { return code; }
103 class MathDotsInset: public MathedInset {
106 MathDotsInset(char const*,int,short st=LM_ST_TEXT);
108 ~MathDotsInset() { };
110 MathedInset *Clone();
114 void Write(FILE *file);
116 void Write(LString &file);
126 class MathSpaceInset: public MathedInset {
129 MathSpaceInset(int sp, short ot=LM_OT_SPACE, short st=LM_ST_TEXT);
131 ~MathSpaceInset() { };
133 MathedInset *Clone();
137 void Write(FILE *file);
139 void Write(LString &file);
141 inline void Metrics();
143 inline void SetSpace(int sp);
145 int GetSpace() { return space; }
153 class MathBigopInset: public MathedInset {
156 MathBigopInset(char const*, int, short st=LM_ST_TEXT);
158 ~MathBigopInset() { };
160 MathedInset *Clone();
164 void Write(FILE *file);
166 void Write(LString &file);
170 inline bool GetLimits() const;
172 inline void SetLimits(bool);
181 //------- All editable insets must be derived from MathParInset.
184 class MathSqrtInset: public MathParInset {
187 MathSqrtInset(short st=LM_ST_TEXT);
189 ~MathSqrtInset() { };
191 MathedInset *Clone();
193 void Draw(int x, int baseline);
195 void Write(FILE *file);
197 void Write(LString &file);
201 bool Inside(int, int);
209 /// Fraction like objects (frac, stackrel, binom)
210 class MathFracInset: public MathParInset {
213 MathFracInset(short ot=LM_OT_FRAC);
217 MathedInset *Clone();
219 void Draw(int x, int baseline);
221 void Write(FILE *file);
223 void Write(LString &file);
227 /** This does the same that SetData(LyxArrayBase*) but for both
228 numerator and denominator at once.
230 void SetData(LyxArrayBase*, LyxArrayBase*);
232 void SetData(LyxArrayBase*);
234 void GetXY(int& x, int& y) const;
236 void SetFocus(int,int);
238 bool Inside(int, int);
240 LyxArrayBase * GetData();
242 bool setArgumentIdx(int i); // was bool Up/down(void);
244 int getArgumentIdx() { return (int)idx; }
246 int getMaxArgumentIdx() { return 1; }
248 void SetStyle(short);
255 int w0, w1, des0, dh;
260 class MathDelimInset: public MathParInset {
263 MathDelimInset(int, int, short st=LM_ST_TEXT);
265 ~MathDelimInset() { };
267 MathedInset *Clone();
271 void Write(FILE *file);
273 void Write(LString &file);
284 /// Decorations over (below) a math object
285 class MathDecorationInset: public MathParInset {
288 MathDecorationInset(int, short st=LM_ST_TEXT);
290 ~MathDecorationInset() { };
292 MathedInset *Clone();
296 void Write(FILE *file);
298 void Write(LString &file);
302 inline bool GetLimits() const;
313 // -------------------- Inline functions ---------------------
317 MathFuncInset::~MathFuncInset()
319 if (fname && GetType()==LM_OT_UNDEF) delete[] fname;
323 bool MathFuncInset::GetLimits() const
325 return (bool)(lims && (GetStyle()==LM_ST_DISPLAY));
329 void MathFuncInset::Write(FILE *file)
331 fprintf(file, "\\%s ", name);
335 void MathFuncInset::Write(LString &file)
343 void MathSpaceInset::Metrics()
345 width = (space) ? space*2: 2;
346 if (space>3) width *= 2;
347 if (space==5) width *= 2;
349 ascent = 4; descent = 0;
353 void MathSpaceInset::SetSpace(int sp)
360 bool MathBigopInset::GetLimits() const
364 return (bool)(sym!=LM_int && sym!=LM_oint && (GetStyle()==LM_ST_DISPLAY));
368 return (bool)(lims>0);
372 void MathBigopInset::SetLimits(bool ls)
378 bool MathDecorationInset::GetLimits() const
380 return (bool)(deco==LM_underbrace||deco==LM_overbrace);