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*);
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; }
97 MathedTextCodes tcode;
99 friend class MathMacroTemplate;
104 class MathMacroArgument: public MathParInset
108 MathMacroArgument() { expnd_mode = false; number = 1; SetType(LM_OT_MACRO_ARG); }
110 MathMacroArgument(int);
112 ~MathMacroArgument() { lyxerr << "help, destroyme!" << endl; }
114 MathedInset *Clone() { return this; }
118 void Draw(int x, int baseline);
122 void Write(string &);
124 void setNumber(int n) { number = n; }
125 /// Is expanded or not
126 void setExpand(bool e) { expnd_mode = e; }
127 /// Is expanded or not
128 bool getExpand() { return expnd_mode; }
138 /// This class contains the macro definition
139 class MathMacroTemplate: public MathParInset
142 /// A template constructor needs all the data
143 MathMacroTemplate(char const*, int na=0, int f=0);
145 ~MathMacroTemplate();
151 void WriteDef(FILE *);
153 void WriteDef(string &);
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;
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;