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() { expnd_mode = false; number = 1; SetType(LM_OT_MACRO_ARG); }
111 MathMacroArgument(int);
113 ~MathMacroArgument() { lyxerr << "help, destroyme!" << std::endl; }
115 MathedInset * Clone() { return this; }
119 void draw(Painter &, int x, int baseline);
121 void Write(std::ostream &, bool fragile);
123 void setNumber(int n) { number = n; }
124 /// Is expanded or not
125 void setExpand(bool e) { expnd_mode = e; }
126 /// Is expanded or not
127 bool getExpand() { return expnd_mode; }
136 /// This class contains the macro definition
137 class MathMacroTemplate: public MathParInset {
139 /// A template constructor needs all the data
141 MathMacroTemplate(char const *, int na = 0, int f = 0);
143 ~MathMacroTemplate();
145 void draw(Painter &, int, int);
149 void WriteDef(std::ostream &, bool fragile);
150 /// useful for special insets
151 void setTCode(MathedTextCodes t) { tcode = t; }
153 MathedTextCodes getTCode() { return tcode; }
155 void setArgument(LyxArrayBase *, int i= 0);
156 /// Number of arguments
157 int getNoArgs() { return nargs; }
159 void GetMacroXY(int, int &, int &) const;
161 MathParInset * getMacroPar(int) const;
163 void SetMacroFocus(int &, int, int);
165 void setEditMode(bool);
167 /// Replace the appropriate arguments with a specific macro's data
168 void update(MathMacro * m = 0);
174 MathedTextCodes tcode;
176 MathMacroArgument * args;
180 friend class MathMacro;
185 typedef MathMacro * MathMacroP;
187 typedef MathMacroTemplate * MathMacroTemplateP;
190 class MathMacroTable {
198 void addTemplate(MathMacroTemplate *);
200 MathMacro * getMacro(char const *) const;
202 MathMacroTemplate * getTemplate(char const *) const;
204 void builtinMacros();
206 static MathMacroTable mathMTable;
212 const int max_macros;
216 MathMacroTemplateP * macro_table;
221 /*----------------------- inlines -------------------------*/
224 bool MathMacro::setArgumentIdx(int i)
226 if (i >= 0 && i < nargs) {
234 int MathMacro::getArgumentIdx()
240 int MathMacro::getMaxArgumentIdx()
247 LyxArrayBase * MathMacro::GetData()
249 return args[idx].array;
254 void MathMacro::SetData(LyxArrayBase * a)
261 MathMacro * MathMacroTable::getMacro(char const * name) const
263 MathMacroTemplate * mt = getTemplate(name);
264 return (mt) ? new MathMacro(mt): 0;