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 &);
53 #ifndef USE_OSTREAM_ONLY
58 bool setArgumentIdx(int);
62 int getMaxArgumentIdx();
66 void GetXY(int &, int &) const;
68 void SetFocus(int, int);
70 LyxArrayBase * GetData();
72 MathedRowSt * getRowSt() const { return args[idx].row; }
74 void SetData(LyxArrayBase *);
76 MathedTextCodes getTCode() { return tcode; }
82 MathMacroTemplate * tmplate;
84 struct MacroArgumentBase {
85 /// Position of the macro
92 MacroArgumentBase() { x = y = 0; array = 0; row = 0; }
94 MacroArgumentBase * args;
100 MathedTextCodes tcode;
102 friend class MathMacroTemplate;
107 class MathMacroArgument: public MathParInset {
110 MathMacroArgument() { expnd_mode = false; number = 1; SetType(LM_OT_MACRO_ARG); }
112 MathMacroArgument(int);
114 ~MathMacroArgument() { lyxerr << "help, destroyme!" << endl; }
116 MathedInset * Clone() { return this; }
120 void draw(Painter &, int x, int baseline);
122 void Write(ostream &);
123 #ifndef USE_OSTREAM_ONLY
125 void Write(string &);
128 void setNumber(int n) { number = n; }
129 /// Is expanded or not
130 void setExpand(bool e) { expnd_mode = e; }
131 /// Is expanded or not
132 bool getExpand() { return expnd_mode; }
142 /// This class contains the macro definition
143 class MathMacroTemplate: public MathParInset {
145 /// A template constructor needs all the data
146 MathMacroTemplate(char const *, int na = 0, int f = 0);
148 ~MathMacroTemplate();
150 void draw(Painter &, int, int);
154 void WriteDef(ostream &);
155 #ifndef USE_OSTREAM_ONLY
157 void WriteDef(string &);
159 /// useful for special insets
160 void setTCode(MathedTextCodes t) { tcode = t; }
162 MathedTextCodes getTCode() { return tcode; }
164 void setArgument(LyxArrayBase *, int i= 0);
165 /// Number of arguments
166 int getNoArgs() { return nargs; }
168 void GetMacroXY(int, int &, int &) const;
170 MathParInset * getMacroPar(int) const;
172 void SetMacroFocus(int &, int, int);
174 void setEditMode(bool);
176 /// Replace the appropriate arguments with a specific macro's data
177 void update(MathMacro * m = 0);
183 MathedTextCodes tcode;
185 MathMacroArgument * args;
189 friend class MathMacro;
194 typedef MathMacro * MathMacroP;
196 typedef MathMacroTemplate * MathMacroTemplateP;
199 class MathMacroTable {
206 void addTemplate(MathMacroTemplate *);
208 MathMacro * getMacro(char const *) const;
210 MathMacroTemplate * getTemplate(char const *) const;
212 void builtinMacros();
214 static MathMacroTable mathMTable;
220 const int max_macros;
224 MathMacroTemplateP * macro_table;
229 /*----------------------- inlines -------------------------*/
232 bool MathMacro::setArgumentIdx(int i)
234 if (i >= 0 && i < nargs) {
242 int MathMacro::getArgumentIdx()
248 int MathMacro::getMaxArgumentIdx()
255 LyxArrayBase * MathMacro::GetData()
257 return args[idx].array;
262 void MathMacro::SetData(LyxArrayBase * a)
269 MathMacro * MathMacroTable::getMacro(char const * name) const
271 MathMacroTemplate * mt = getTemplate(name);
272 return (mt) ? new MathMacro(mt): 0;