4 * Purpose: Declaration of macro class for mathed
5 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
6 * Created: November 1996
7 * Description: WYSIWYG math macros
11 * Copyright: 1996, 1997 Alejandro Aguilar Sierra
13 * Version: 0.2, Mathed & Lyx project.
15 * This code is under the GNU General Public Licence version 2 or later.
24 #include "math_defs.h"
28 typedef MathParInset * MathParInsetP;
30 typedef LyxArrayBase * LyxArrayBaseP;
32 class MathMacroTemplate;
35 /// This class contains the data for a macro
36 class MathMacro : public MathParInset
39 /// A macro can only be builded from an existing template
41 MathMacro(MathMacroTemplate *);
42 /// or from another macro.
44 MathMacro(MathMacro *);
48 void draw(Painter &, int, int);
52 MathedInset * Clone();
54 void Write(std::ostream &, bool fragile);
56 bool setArgumentIdx(int);
60 int getMaxArgumentIdx();
64 void GetXY(int &, int &) const;
66 void SetFocus(int, int);
68 LyxArrayBase * GetData();
70 MathedRowSt * getRowSt() const { return args[idx].row; }
72 void SetData(LyxArrayBase *);
74 MathedTextCodes getTCode() { return tcode; }
80 MathMacroTemplate * tmplate;
82 struct MacroArgumentBase {
83 /// Position of the macro
90 MacroArgumentBase() { x = y = 0; array = 0; row = 0; }
92 MacroArgumentBase * args;
98 MathedTextCodes tcode;
100 friend class MathMacroTemplate;
105 class MathMacroArgument: public MathParInset {
108 MathMacroArgument() {
111 SetType(LM_OT_MACRO_ARG);
115 MathMacroArgument(int);
117 ~MathMacroArgument() { lyxerr << "help, destroyme!" << std::endl; }
119 MathedInset * Clone() { return this; }
123 void draw(Painter &, int x, int baseline);
125 void Write(std::ostream &, bool fragile);
127 void setNumber(int n) { number = n; }
128 /// Is expanded or not
129 void setExpand(bool e) { expnd_mode = e; }
130 /// Is expanded or not
131 bool getExpand() { return expnd_mode; }
140 /// This class contains the macro definition
141 class MathMacroTemplate: public MathParInset {
143 /// A template constructor needs all the data
145 MathMacroTemplate(char const *, int na = 0, int f = 0);
147 ~MathMacroTemplate();
149 void draw(Painter &, int, int);
153 void WriteDef(std::ostream &, bool fragile);
154 /// useful for special insets
155 void setTCode(MathedTextCodes t) { tcode = t; }
157 MathedTextCodes getTCode() { return tcode; }
159 void setArgument(LyxArrayBase *, int i= 0);
160 /// Number of arguments
161 int getNoArgs() { return nargs; }
163 void GetMacroXY(int, int &, int &) const;
165 MathParInset * getMacroPar(int) const;
167 void SetMacroFocus(int &, int, int);
169 void setEditMode(bool);
171 /// Replace the appropriate arguments with a specific macro's data
172 void update(MathMacro * m = 0);
178 MathedTextCodes tcode;
180 MathMacroArgument * args;
184 friend class MathMacro;
189 typedef MathMacro * MathMacroP;
191 typedef MathMacroTemplate * MathMacroTemplateP;
194 class MathMacroTable {
202 void addTemplate(MathMacroTemplate *);
204 MathMacro * getMacro(char const *) const;
206 MathMacroTemplate * getTemplate(char const *) const;
208 void builtinMacros();
210 static MathMacroTable mathMTable;
216 const int max_macros;
220 MathMacroTemplateP * macro_table;
225 /*----------------------- inlines -------------------------*/
228 bool MathMacro::setArgumentIdx(int i)
230 if (i >= 0 && i < nargs) {
238 int MathMacro::getArgumentIdx()
244 int MathMacro::getMaxArgumentIdx()
251 LyxArrayBase * MathMacro::GetData()
253 return args[idx].array;
258 void MathMacro::SetData(LyxArrayBase * a)
265 MathMacro * MathMacroTable::getMacro(char const * name) const
267 MathMacroTemplate * mt = getTemplate(name);
268 return (mt) ? new MathMacro(mt): 0;