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
40 MathMacro(MathMacroTemplate *);
41 /// or from another macro.
42 MathMacro(MathMacro *);
46 void draw(Painter &, int, int);
50 MathedInset * Clone();
52 void Write(ostream &);
54 bool setArgumentIdx(int);
58 int getMaxArgumentIdx();
62 void GetXY(int &, int &) const;
64 void SetFocus(int, int);
66 LyxArrayBase * GetData();
68 MathedRowSt * getRowSt() const { return args[idx].row; }
70 void SetData(LyxArrayBase *);
72 MathedTextCodes getTCode() { return tcode; }
78 MathMacroTemplate * tmplate;
80 struct MacroArgumentBase {
81 /// Position of the macro
88 MacroArgumentBase() { x = y = 0; array = 0; row = 0; }
90 MacroArgumentBase * args;
96 MathedTextCodes tcode;
98 friend class MathMacroTemplate;
103 class MathMacroArgument: public MathParInset {
106 MathMacroArgument() { expnd_mode = false; number = 1; SetType(LM_OT_MACRO_ARG); }
108 MathMacroArgument(int);
110 ~MathMacroArgument() { lyxerr << "help, destroyme!" << endl; }
112 MathedInset * Clone() { return this; }
116 void draw(Painter &, int x, int baseline);
118 void Write(ostream &);
120 void setNumber(int n) { number = n; }
121 /// Is expanded or not
122 void setExpand(bool e) { expnd_mode = e; }
123 /// Is expanded or not
124 bool getExpand() { return expnd_mode; }
133 /// This class contains the macro definition
134 class MathMacroTemplate: public MathParInset {
136 /// A template constructor needs all the data
137 MathMacroTemplate(char const *, int na = 0, int f = 0);
139 ~MathMacroTemplate();
141 void draw(Painter &, int, int);
145 void WriteDef(ostream &);
146 /// useful for special insets
147 void setTCode(MathedTextCodes t) { tcode = t; }
149 MathedTextCodes getTCode() { return tcode; }
151 void setArgument(LyxArrayBase *, int i= 0);
152 /// Number of arguments
153 int getNoArgs() { return nargs; }
155 void GetMacroXY(int, int &, int &) const;
157 MathParInset * getMacroPar(int) const;
159 void SetMacroFocus(int &, int, int);
161 void setEditMode(bool);
163 /// Replace the appropriate arguments with a specific macro's data
164 void update(MathMacro * m = 0);
170 MathedTextCodes tcode;
172 MathMacroArgument * args;
176 friend class MathMacro;
181 typedef MathMacro * MathMacroP;
183 typedef MathMacroTemplate * MathMacroTemplateP;
186 class MathMacroTable {
193 void addTemplate(MathMacroTemplate *);
195 MathMacro * getMacro(char const *) const;
197 MathMacroTemplate * getTemplate(char const *) const;
199 void builtinMacros();
201 static MathMacroTable mathMTable;
207 const int max_macros;
211 MathMacroTemplateP * macro_table;
216 /*----------------------- inlines -------------------------*/
219 bool MathMacro::setArgumentIdx(int i)
221 if (i >= 0 && i < nargs) {
229 int MathMacro::getArgumentIdx()
235 int MathMacro::getMaxArgumentIdx()
242 LyxArrayBase * MathMacro::GetData()
244 return args[idx].array;
249 void MathMacro::SetData(LyxArrayBase * a)
256 MathMacro * MathMacroTable::getMacro(char const * name) const
258 MathMacroTemplate * mt = getTemplate(name);
259 return (mt) ? new MathMacro(mt): 0;