]> git.lyx.org Git - lyx.git/blob - src/mathed/MathMacroTemplate.h
b90c8a96cb0c01d4f283118c3befef7fa0c14d8c
[lyx.git] / src / mathed / MathMacroTemplate.h
1 // -*- C++ -*-
2 /**
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.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author André Pönitz
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef MATH_MACROTEMPLATE_H
14 #define MATH_MACROTEMPLATE_H
15
16 #include "InsetMathNest.h"
17 #include "MacroTable.h"
18 #include "MathData.h"
19
20 #include "support/types.h"
21
22
23 namespace lyx {
24
25 /// This class contains the macro definition.
26 class MathMacroTemplate : public InsetMathNest {
27 public:
28         ///
29         MathMacroTemplate();
30         ///
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());
36         ///
37         explicit MathMacroTemplate(const docstring & str);
38         ///
39         EDITABLE editable() const { return HIGHLY_EDITABLE; }
40         ///
41         void read(Buffer const &, Lexer & lex);
42         ///
43         void write(Buffer const &, std::ostream & os) const;
44         ///
45         void write(WriteStream & os) const;
46         ///
47         int plaintext(Buffer const &, odocstream &,
48                 OutputParams const &) const;
49
50         ///
51         docstring name() const;
52         /// check name and possible other formal properties
53         bool validMacro() const;
54         ///
55         bool validName() const;
56         ///
57         MacroData asMacroData() const;
58         ///
59         void draw(PainterInfo & pi, int x, int y) const;
60         ///
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; }
66         ///
67         InsetCode lyxCode() const { return MATHMACRO_CODE; }
68
69 protected:
70         ///
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;
75
76 private:
77         virtual Inset * clone() const;
78
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);
83         ///
84         void insertParameter(Cursor & cur, int pos, bool greedy = false);
85         ///
86         void removeParameter(Cursor & cur, int pos, bool greedy = false );
87         ///
88         void makeOptional(Cursor & cur);
89         ///
90         void makeNonOptional(Cursor & cur);
91         ///
92         idx_type defIdx() const { return optionals_ + 1; }
93         /// index of default value cell of optional parameter (#1 -> n=0)
94         idx_type optIdx(idx_type n) const { return n + 1; }
95         ///
96         idx_type displayIdx() const { return optionals_ + 2; }
97         /// The label with some holes to edit
98         mutable MathData label_;
99         ///
100         mutable int numargs_;
101         ///
102         int optionals_;
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_;
107 };
108
109
110 } // namespace lyx
111
112 #endif