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