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.
17 #ifndef __MATH_MACRO__
18 #define __MATH_MACRO__
24 #include "math_defs.h"
27 typedef MathParInset* MathParInsetP;
29 typedef LyxArrayBase *LyxArrayBaseP;
31 class MathMacroTemplate;
34 /// This class contains the data for a macro
35 class MathMacro: public MathParInset
38 /// A macro can only be builded from an existing template
39 MathMacro(MathMacroTemplate *);
40 /// or from another macro.
41 MathMacro(MathMacro*);
55 bool setArgumentIdx(int);
59 int getMaxArgumentIdx();
63 void GetXY(int&, int&) const;
65 void SetFocus(int, int);
67 LyxArrayBase *GetData();
69 MathedRowSt *getRowSt() const { return args[idx].row; }
71 void SetData(LyxArrayBase *);
73 MathedTextCodes getTCode() { return tcode; }
79 MathMacroTemplate *tmplate;
81 struct MacroArgumentBase {
82 /// Position of the macro
89 MacroArgumentBase() { x = y = 0; array = 0; row = 0; }
96 MathedTextCodes tcode;
98 friend class MathMacroTemplate;
103 class MathMacroArgument: public MathParInset
107 MathMacroArgument() { expnd_mode = false; number = 1; SetType(LM_OT_MACRO_ARG); }
109 MathMacroArgument(int);
111 ~MathMacroArgument() { fprintf(stderr, "help, destroyme!\n"); }
113 MathedInset *Clone() { return this; }
117 void Draw(int x, int baseline);
121 void Write(string &);
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; }
137 /// This class contains the macro definition
138 class MathMacroTemplate: public MathParInset
141 /// A template constructor needs all the data
142 MathMacroTemplate(char const*, int na=0, int f=0);
144 ~MathMacroTemplate();
150 void WriteDef(FILE *);
152 void WriteDef(string &);
153 /// useful for special insets
154 void setTCode(MathedTextCodes t) { tcode = t; }
156 MathedTextCodes getTCode() { return tcode; }
158 void setArgument(LyxArrayBase *, int i=0);
159 /// Number of arguments
160 int getNoArgs() { return nargs; }
162 void GetMacroXY(int, int&, int&) const;
164 MathParInset *getMacroPar(int) const;
166 void SetMacroFocus(int&, int, int);
168 void setEditMode(bool);
170 /// Replace the appropriate arguments with a specific macro's data
171 void update(MathMacro* m=0);
177 MathedTextCodes tcode;
179 MathMacroArgument *args;
183 friend class MathMacro;
188 typedef MathMacro *MathMacroP;
190 typedef MathMacroTemplate *MathMacroTemplateP;
201 void addTemplate(MathMacroTemplate *);
203 MathMacro *getMacro(char const*) const;
205 MathMacroTemplate *getTemplate(char const*) const;
207 void builtinMacros();
209 static MathMacroTable mathMTable;
215 const int max_macros;
219 MathMacroTemplateP *macro_table;
224 /*----------------------- inlines -------------------------*/
227 bool MathMacro::setArgumentIdx(int i)
229 if (i>=0 && i<nargs) {
237 int MathMacro::getArgumentIdx()
243 int MathMacro::getMaxArgumentIdx()
250 LyxArrayBase *MathMacro::GetData()
252 return args[idx].array;
257 void MathMacro::SetData(LyxArrayBase *a)
264 MathMacro *MathMacroTable::getMacro(char const* name) const
266 MathMacroTemplate *mt = getTemplate(name);
267 return (mt) ? new MathMacro(mt): 0;