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(FILE * file);
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(FILE * file);
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);
111 MathedInset * Clone();
115 void Write(FILE * file);
117 void Write(string & file);
127 class MathSpaceInset: public MathedInset {
130 MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
134 MathedInset * Clone();
138 void Write(FILE * file);
140 void Write(string & file);
142 inline void Metrics();
144 inline void SetSpace(int sp);
146 int GetSpace() { return space; }
154 class MathBigopInset: public MathedInset {
157 MathBigopInset(char const *, int, short st = LM_ST_TEXT);
161 MathedInset * Clone();
165 void Write(FILE * file);
167 void Write(string & file);
171 inline bool GetLimits() const;
173 inline void SetLimits(bool);
182 //------- All editable insets must be derived from MathParInset.
185 class MathSqrtInset: public MathParInset {
188 MathSqrtInset(short st = LM_ST_TEXT);
192 MathedInset * Clone();
194 void Draw(int x, int baseline);
196 void Write(FILE * file);
198 void Write(string & file);
202 bool Inside(int, int);
210 /// Fraction like objects (frac, stackrel, binom)
211 class MathFracInset: public MathParInset {
214 MathFracInset(short ot = LM_OT_FRAC);
218 MathedInset * Clone();
220 void Draw(int x, int baseline);
222 void Write(FILE * file);
224 void Write(string & file);
228 /** This does the same that SetData(LyxArrayBase*) but for both
229 numerator and denominator at once.
231 void SetData(LyxArrayBase *, LyxArrayBase *);
233 void SetData(LyxArrayBase *);
235 void GetXY(int & x, int & y) const;
237 void SetFocus(int, int);
239 bool Inside(int, int);
241 LyxArrayBase * GetData();
243 bool setArgumentIdx(int i); // was bool Up/down(void);
245 int getArgumentIdx() { return int(idx); }
247 int getMaxArgumentIdx() { return 1; }
249 void SetStyle(short);
256 int w0, w1, des0, dh;
261 class MathDelimInset: public MathParInset {
264 MathDelimInset(int, int, short st = LM_ST_TEXT);
268 MathedInset * Clone();
272 void Write(FILE * file);
274 void Write(string & file);
285 /// Decorations over (below) a math object
286 class MathDecorationInset: public MathParInset {
289 MathDecorationInset(int, short st = LM_ST_TEXT);
291 ~MathDecorationInset() {}
293 MathedInset * Clone();
297 void Write(FILE * file);
299 void Write(string & file);
303 inline bool GetLimits() const;
314 // -------------------- Inline functions ---------------------
318 MathFuncInset::~MathFuncInset()
320 if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
325 bool MathFuncInset::GetLimits() const
327 return bool(lims && (GetStyle() == LM_ST_DISPLAY));
332 void MathFuncInset::Write(FILE * file)
334 fprintf(file, "\\%s ", name);
339 void MathFuncInset::Write(string & file)
348 void MathSpaceInset::Metrics()
350 width = (space) ? space * 2 : 2;
351 if (space>3) width *= 2;
352 if (space == 5) width *= 2;
354 ascent = 4; descent = 0;
359 void MathSpaceInset::SetSpace(int sp)
367 bool MathBigopInset::GetLimits() const
371 return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
380 void MathBigopInset::SetLimits(bool ls)
387 bool MathDecorationInset::GetLimits() const
389 return deco == LM_underbrace || deco == LM_overbrace;