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: (c) 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
40 MathMacro(MathMacroTemplate *);
41 /// or from another macro.
42 MathMacro(MathMacro *);
46 void draw(Painter &, int, int);
50 MathedInset * Clone();
52 void Write(ostream &);
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
109 MathMacroArgument() { expnd_mode = false; number = 1; SetType(LM_OT_MACRO_ARG); }
111 MathMacroArgument(int);
113 ~MathMacroArgument() { lyxerr << "help, destroyme!" << endl; }
115 MathedInset * Clone() { return this; }
119 void draw(Painter &, int x, int baseline);
121 void Write(ostream &);
123 void Write(string &);
125 void setNumber(int n) { number = n; }
126 /// Is expanded or not
127 void setExpand(bool e) { expnd_mode = e; }
128 /// Is expanded or not
129 bool getExpand() { return expnd_mode; }
139 /// This class contains the macro definition
140 class MathMacroTemplate: public MathParInset
143 /// A template constructor needs all the data
144 MathMacroTemplate(char const *, int na = 0, int f = 0);
146 ~MathMacroTemplate();
148 void draw(Painter &, int, int);
152 void WriteDef(ostream &);
154 void WriteDef(string &);
155 /// useful for special insets
156 void setTCode(MathedTextCodes t) { tcode = t; }
158 MathedTextCodes getTCode() { return tcode; }
160 void setArgument(LyxArrayBase *, int i= 0);
161 /// Number of arguments
162 int getNoArgs() { return nargs; }
164 void GetMacroXY(int, int &, int &) const;
166 MathParInset * getMacroPar(int) const;
168 void SetMacroFocus(int &, int, int);
170 void setEditMode(bool);
172 /// Replace the appropriate arguments with a specific macro's data
173 void update(MathMacro * m = 0);
179 MathedTextCodes tcode;
181 MathMacroArgument * args;
185 friend class MathMacro;
190 typedef MathMacro * MathMacroP;
192 typedef MathMacroTemplate * MathMacroTemplateP;
203 void addTemplate(MathMacroTemplate *);
205 MathMacro * getMacro(char const *) const;
207 MathMacroTemplate * getTemplate(char const *) const;
209 void builtinMacros();
211 static MathMacroTable mathMTable;
217 const int max_macros;
221 MathMacroTemplateP * macro_table;
226 /*----------------------- inlines -------------------------*/
229 bool MathMacro::setArgumentIdx(int i)
231 if (i >= 0 && i < nargs) {
239 int MathMacro::getArgumentIdx()
245 int MathMacro::getMaxArgumentIdx()
252 LyxArrayBase * MathMacro::GetData()
254 return args[idx].array;
259 void MathMacro::SetData(LyxArrayBase * a)
266 MathMacro * MathMacroTable::getMacro(char const * name) const
268 MathMacroTemplate * mt = getTemplate(name);
269 return (mt) ? new MathMacro(mt): 0;