3 * \file math_macrotemplate.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
10 * Full author contact details are available in file CREDITS.
13 #ifndef MATH_MACROTEMPLATE_H
14 #define MATH_MACROTEMPLATE_H
16 #include "InsetMathNest.h"
17 #include "MacroTable.h"
20 #include "support/types.h"
25 /// This class contains the macro definition.
26 class MathMacroTemplate : public InsetMathNest {
31 MathMacroTemplate(docstring const & name, int nargs, int optional,
32 docstring const & type,
33 std::vector<MathData> const & optionalValues = std::vector<MathData>(),
34 MathData const & def = MathData(),
35 MathData const & display = MathData());
37 explicit MathMacroTemplate(const docstring & str);
39 EDITABLE editable() const { return HIGHLY_EDITABLE; }
41 void read(Buffer const &, Lexer & lex);
43 void write(Buffer const &, std::ostream & os) const;
45 void write(WriteStream & os) const;
47 int plaintext(Buffer const &, odocstream &,
48 OutputParams const &) const;
51 docstring name() const;
52 /// check name and possible other formal properties
53 bool validMacro() const;
55 bool validName() const;
57 MacroData asMacroData() const;
59 void draw(PainterInfo & pi, int x, int y) const;
61 void metrics(MetricsInfo & mi, Dimension & dim) const;
62 /// identifies macro templates
63 MathMacroTemplate * asMacroTemplate() { return this; }
64 /// identifies macro templates
65 MathMacroTemplate const * asMacroTemplate() const { return this; }
67 InsetCode lyxCode() const { return MATHMACRO_CODE; }
71 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
72 /// do we want to handle this event?
73 bool getStatus(Cursor & cur, FuncRequest const & cmd,
74 FuncStatus & status) const;
77 virtual Inset * clone() const;
79 /// remove #n with from<=n<=to
80 void removeArguments(Cursor & cur, int from, int to);
81 /// shift every #n with from<=n, i.e. #n -> #(n-by)
82 void shiftArguments(size_t from, int by);
84 void insertParameter(Cursor & cur, int pos, bool greedy = false);
86 void removeParameter(Cursor & cur, int pos, bool greedy = false );
88 void makeOptional(Cursor & cur);
90 void makeNonOptional(Cursor & cur);
92 pos_type defIdx() const { return optionals_ + 1; }
93 /// index of default value cell of optional parameter (#1 -> n=0)
94 pos_type optIdx(int n) const { return n + 1; }
96 pos_type displayIdx() const { return optionals_ + 2; }
97 /// The label with some holes to edit
98 mutable MathData label_;
100 mutable int numargs_;
103 /// keeps the old optional default value when an optional argument is disabled
104 std::vector<MathData> optionalValues_;
105 /// newcommand or renewcommand or def
106 mutable docstring type_;