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.
26 #include "math_parinset.h"
29 class MathMacroTemplate;
32 /// This class contains the data for a macro
33 class MathMacro : public MathParInset
36 /// A macro can only be builded from an existing template
38 MathMacro(MathMacroTemplate *);
39 /// or from another macro.
41 MathMacro(MathMacro *);
45 void draw(Painter &, int, int);
49 MathedInset * Clone();
51 void Write(std::ostream &, bool fragile);
53 bool setArgumentIdx(int);
55 int getArgumentIdx() const;
57 int getMaxArgumentIdx() const;
59 int GetColumns() const;
61 void GetXY(int &, int &) const;
63 void SetFocus(int, int);
65 MathedArray * GetData();
67 MathedRowSt * getRowSt() const { return args_[idx].row; }
69 void SetData(MathedArray *);
71 MathedTextCodes getTCode() const { return tcode; }
73 bool Permit(short) const;
77 MathMacroTemplate * tmplate;
79 struct MacroArgumentBase {
80 /// Position of the macro
87 MacroArgumentBase() { x = y = 0; array = 0; row = 0; }
89 std::vector<MacroArgumentBase> args_;
95 MathedTextCodes tcode;
97 friend class MathMacroTemplate;
102 class MathMacroArgument: public MathParInset {
105 MathMacroArgument() {
108 SetType(LM_OT_MACRO_ARG);
112 MathMacroArgument(int);
114 ~MathMacroArgument() { lyxerr << "help, destroyme!" << std::endl; }
116 MathedInset * Clone() { return this; }
120 void draw(Painter &, int x, int baseline);
122 void Write(std::ostream &, bool fragile);
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() const { return expnd_mode; }
137 /// This class contains the macro definition
138 class MathMacroTemplate: public MathParInset {
140 /// A template constructor needs all the data
142 MathMacroTemplate(string const &, int na = 0, int f = 0);
144 ~MathMacroTemplate();
146 void draw(Painter &, int, int);
150 void WriteDef(std::ostream &, bool fragile);
151 /// useful for special insets
152 void setTCode(MathedTextCodes t) { tcode = t; }
154 MathedTextCodes getTCode() const { return tcode; }
156 void setArgument(MathedArray *, int i= 0);
157 /// Number of arguments
158 int getNoArgs() const { return nargs; }
160 void GetMacroXY(int, int &, int &) const;
162 MathParInset * getMacroPar(int) const;
164 void SetMacroFocus(int &, int, int);
166 void setEditMode(bool);
168 /// Replace the appropriate arguments with a specific macro's data
169 void update(MathMacro * m = 0);
175 MathedTextCodes tcode;
177 std::vector<MathMacroArgument> args_;
181 friend class MathMacro;
186 typedef MathMacro * MathMacroP;
188 typedef MathMacroTemplate * MathMacroTemplateP;
191 class MathMacroTable {
194 void addTemplate(MathMacroTemplate *);
196 MathMacro * getMacro(string const &) const;
198 MathMacroTemplate * getTemplate(string const &) const;
200 void builtinMacros();
202 static MathMacroTable mathMTable;
208 typedef std::vector<MathMacroTemplateP> table_type;
210 typedef table_type::size_type size_type;
212 table_type macro_table;
217 /*----------------------- inlines -------------------------*/
220 bool MathMacro::setArgumentIdx(int i)
222 if (i >= 0 && i < nargs) {
230 int MathMacro::getArgumentIdx() const
236 int MathMacro::getMaxArgumentIdx() const
243 MathedArray * MathMacro::GetData()
245 return args_[idx].array;
250 void MathMacro::SetData(MathedArray * a)
252 args_[idx].array = a;
257 MathMacro * MathMacroTable::getMacro(string const & name) const
259 MathMacroTemplate * mt = getTemplate(name);
260 return (mt) ? new MathMacro(mt): 0;