]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathMacroTemplate.h
Fix functions that used functions but did not defined it
[lyx.git] / src / mathed / InsetMathMacroTemplate.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
21 namespace lyx {
22
23 class OutputParams;
24 class XMLStream;
25
26 /// This class contains the macro definition.
27 class InsetMathMacroTemplate : public InsetMathNest {
28 public:
29         ///
30         explicit InsetMathMacroTemplate(Buffer * buf);
31         ///
32         InsetMathMacroTemplate(Buffer * buf, docstring const & name, int numargs,
33                                                    int optionals, MacroType type);
34         ///
35         InsetMathMacroTemplate(Buffer * buf, docstring const & name, int numargs,
36                 int optionals, MacroType type,
37                 std::vector<MathData> const & optionalValues,
38                 MathData const & def, MathData const & display);
39         /// parses from string, returns false if failed
40         bool fromString (const docstring & str);
41         ///
42         bool editable() const override { return true; }
43         ///
44         void edit(Cursor & cur, bool front, EntryDirection entry_from) override;
45         ///
46         Inset * editXY(Cursor & cur, int x, int y) override;
47         ///
48         bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
49         ///
50         void read(support::Lexer & lex) override;
51         ///
52         void write(std::ostream & os) const override;
53         ///
54         void write(TeXMathStream & os) const override;
55         /// Output LaTeX code, but assume that the macro is not defined yet
56         /// if overwriteRedefinition is true
57         int write(TeXMathStream & os, bool overwriteRedefinition) const;
58         /// Nothing happens. This is simply to suppress the default output.
59         docstring xhtml(XMLStream &, OutputParams const &) const override;
60         ///
61         int plaintext(odocstringstream &, OutputParams const &, size_t) const override;
62         ///
63         bool inheritFont() const override { return false; }
64         ///
65         docstring name() const override;
66         ///
67         void getDefaults(std::vector<docstring> & defaults) const;
68         ///
69         docstring definition() const;
70         ///
71         docstring displayDefinition() const;
72         ///
73         size_t numArgs() const;
74         ///
75         size_t numOptionals() const;
76         ///
77         bool redefinition() const { return redefinition_; }
78         ///
79         MacroType type() const { return type_; }
80
81         /// check name and possible other formal properties
82         bool validMacro() const;
83         ///
84         bool validName() const;
85         /// Remove everything from the name which makes it invalid
86         /// and return true iff it is valid.
87         bool fixNameAndCheckIfValid();
88
89         /// request "external features"
90         void validate(LaTeXFeatures &) const override;
91
92         /// decide whether its a redefinition
93         void updateToContext(MacroContext const & mc);
94
95         ///
96         void draw(PainterInfo & pi, int x, int y) const override;
97         ///
98         void metrics(MetricsInfo & mi, Dimension & dim) const override;
99         /// identifies macro templates
100         InsetMathMacroTemplate * asMacroTemplate() override { return this; }
101         /// identifies macro templates
102         InsetMathMacroTemplate const * asMacroTemplate() const override { return this; }
103         ///
104         InsetCode lyxCode() const override { return MATHMACRO_CODE; }
105         ///
106         void infoize(odocstream & os) const override;
107         ///
108         std::string contextMenuName() const override;
109         ///
110         void addToToc(DocIterator const & di, bool output_active,
111                                   UpdateType utype, TocBackend & backend) const override;
112 protected:
113         ///
114         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
115         /// do we want to handle this event?
116         bool getStatus(Cursor & cur, FuncRequest const & cmd,
117                 FuncStatus & status) const override;
118
119 private:
120         friend class InsetLabelBox;
121         friend class InsetDisplayLabelBox;
122
123         ///
124         Inset * clone() const override;
125
126         /// remove #n with from<=n<=to
127         void removeArguments(Cursor & cur, DocIterator const & inset_pos,
128                 int from, int to);
129         /// shift every #n with from<=n, i.e. #n -> #(n-by)
130         void shiftArguments(size_t from, int by);
131         ///
132         void insertParameter(Cursor & cur, DocIterator const & inset_pos,
133                 int pos, bool greedy = false, bool addarg = true);
134         ///
135         void removeParameter(Cursor & cur, DocIterator const & inset_pos,
136                 int pos, bool greedy = false);
137         ///
138         void makeOptional(Cursor & cur, DocIterator const & inset_pos);
139         ///
140         void makeNonOptional(Cursor & cur, DocIterator const & inset_pos);
141         ///
142         idx_type defIdx() const { return optionals_ + 1; }
143         /// index of default value cell of optional parameter (#1 -> n=0)
144         idx_type optIdx(idx_type n) const { return n + 1; }
145         ///
146         idx_type displayIdx() const { return optionals_ + 2; }
147         ///
148         void updateLook() const;
149         /// look through the macro for #n arguments
150         int maxArgumentInDefinition() const;
151         /// add missing #n arguments up to \c maxArg
152         void insertMissingArguments(int maxArg);
153         /// change the arity
154         void changeArity(Cursor & cur, DocIterator const & inset_pos,
155                 int newNumArg);
156         /// find arguments in definition and adapt the arity accordingly
157         void commitEditChanges(Cursor & cur, DocIterator const & inset_pos);
158         /// The representation of the macro template, with some holes to edit
159         mutable MathData look_;
160         ///
161         mutable int numargs_;
162         ///
163         mutable int argsInLook_;
164         ///
165         int optionals_;
166         /// keeps the old optional default value when an
167         /// optional argument is disabled
168         std::vector<MathData> optionalValues_;
169
170         /// (re)newcommand or def
171         mutable MacroType type_;
172         /// defined before already?
173         bool redefinition_;
174         ///
175         void createLook(int args) const;
176         ///
177         mutable bool lookOutdated_;
178         /// true if in pre-calculations of metrics to get height of boxes
179         mutable bool premetrics_;
180         ///
181         mutable int labelBoxAscent_;
182         ///
183         mutable int labelBoxDescent_;
184         ///
185         bool premetrics() const { return premetrics_; }
186         ///
187         int commonLabelBoxAscent() const { return labelBoxAscent_; }
188         ///
189         int commonLabelBoxDescent() const { return labelBoxDescent_; }
190 };
191
192
193 } // namespace lyx
194
195 #endif