]> git.lyx.org Git - lyx.git/blob - src/mathed/MathMacro.h
Pimpl MathMacro
[lyx.git] / src / mathed / MathMacro.h
1 // -*- C++ -*-
2 /**
3  * \file MathMacro.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_MACRO_H
14 #define MATH_MACRO_H
15
16 #include "InsetMathNest.h"
17 #include "MacroTable.h"
18 #include "MathData.h"
19
20 #include <map>
21
22 namespace lyx {
23
24 /// This class contains the data for a macro.
25 class MathMacro : public InsetMathNest {
26 public:
27         /// A macro can be built from an existing template
28         MathMacro(Buffer * buf, docstring const & name);
29         ///
30         MathMacro(MathMacro const &);
31         ///
32         MathMacro & operator=(MathMacro const &);
33         ///
34         ~MathMacro();
35         ///
36         virtual MathMacro * asMacro() { return this; }
37         ///
38         virtual MathMacro const * asMacro() const { return this; }
39         ///
40         void draw(PainterInfo & pi, int x, int y) const;
41         /// draw selection background
42         void drawSelection(PainterInfo & pi, int x, int y) const;
43         /// draw decorations.
44         void drawDecoration(PainterInfo & pi, int x, int y) const
45         { drawMarkers2(pi, x, y); }
46         ///
47         void metrics(MetricsInfo & mi, Dimension & dim) const;
48         ///
49         int kerning(BufferView const * bv) const;
50         /// get cursor position
51         void cursorPos(BufferView const & bv, CursorSlice const & sl,
52                 bool boundary, int & x, int & y) const;
53         ///
54         void edit(Cursor & cur, bool front, EntryDirection entry_from);
55         ///
56         Inset * editXY(Cursor & cur, int x, int y);
57
58         /// target pos when we enter the inset while moving forward
59         bool idxFirst(Cursor &) const;
60         /// target pos when we enter the inset while moving backwards
61         bool idxLast(Cursor &) const;
62
63         ///
64         virtual bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
65
66         /// Remove cell (starting from 0)
67         void removeArgument(pos_type pos);
68         /// Insert empty cell (starting from 0)
69         void insertArgument(pos_type pos);
70
71         ///
72         void validate(LaTeXFeatures &) const;
73
74         ///
75         void write(WriteStream & os) const;
76         ///
77         void normalize(NormalStream & os) const;
78         ///
79         void maple(MapleStream &) const;
80         ///
81         void maxima(MaximaStream &) const;
82         ///
83         void mathematica(MathematicaStream &) const;
84         ///
85         void mathmlize(MathStream &) const;
86         ///
87         void htmlize(HtmlStream &) const;
88         ///
89         void octave(OctaveStream &) const;
90         ///
91         void infoize(odocstream &) const;
92         ///
93         void infoize2(odocstream &) const;
94
95         /// fold the macro in the next metrics call
96         void fold(Cursor & cur);
97         /// unfold the macro in the next metrics call
98         void unfold(Cursor & cur);
99         /// will it be folded or unfolded in the next metric call?
100         bool folded() const;
101
102         enum DisplayMode {
103                 DISPLAY_INIT,
104                 DISPLAY_INTERACTIVE_INIT,
105                 DISPLAY_UNFOLDED,
106                 DISPLAY_NORMAL
107         };
108
109         ///
110         DisplayMode displayMode() const;
111
112         ///
113         bool extraBraces() const;
114
115         ///
116         docstring name() const;
117         ///
118         docstring macroName() const;
119         ///
120         bool validName() const;
121         ///
122         size_t arity() const;
123
124         ///
125         size_t optionals() const;
126         ///
127         void setOptionals(int n);
128         /// Return the maximal number of arguments the macro is greedy for.
129         size_t appetite() const;
130         ///
131         InsetCode lyxCode() const { return MATH_MACRO_CODE; }
132
133 protected:
134         friend class MathData;
135         friend class ArgumentProxy;
136         friend class Cursor;
137
138         /// update the display mode (should only be called after detaching arguments)
139         void setDisplayMode(DisplayMode mode, int appetite = -1);
140         /// compute the next display mode
141         DisplayMode computeDisplayMode() const;
142         /// update macro definition
143         void updateMacro(MacroContext const & mc);
144         /// check if macro definition changed, argument changed etc. and adapt
145         void updateRepresentation(Cursor * cur, MacroContext const & mc, UpdateType);
146         /// empty macro, put arguments into args, possibly strip arity-attachedArgsNum_ empty ones.
147         /// Includes the optional arguments.
148         void detachArguments(std::vector<MathData> & args, bool strip);
149         /// attach arguments (maybe less than arity at the end of an MathData),
150         /// including the optional ones (even if it can be empty here)
151         void attachArguments(std::vector<MathData> const & args, size_t arity, int optionals);
152         ///
153         MacroData const * macro();
154         ///
155         bool editMetrics(BufferView const * bv) const;
156
157 private:
158         ///
159         virtual Inset * clone() const;
160         ///
161         bool editMode(BufferView const * bv) const;
162
163         ///
164         class Private;
165         ///
166         Private * d;
167         /// update lock to avoid loops
168         class UpdateLocker;
169         friend class UpdateLocker;
170
171 public:
172         ///
173         bool completionSupported(Cursor const &) const;
174         ///
175         bool inlineCompletionSupported(Cursor const & cur) const;
176         ///
177         bool automaticInlineCompletion() const;
178         ///
179         bool automaticPopupCompletion() const;
180         ///
181         CompletionList const * createCompletionList(Cursor const & cur) const;
182         ///
183         docstring completionPrefix(Cursor const & cur) const;
184         ///
185         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
186         ///
187         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
188 };
189
190 } // namespace lyx
191 #endif