3 * \file InsetMathMacro.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.
16 #include "InsetMathNest.h"
17 #include "MacroTable.h"
24 /// This class contains the data for a macro.
25 class InsetMathMacro : public InsetMathNest {
27 /// A macro can be built from an existing template
28 InsetMathMacro(Buffer * buf, docstring const & name);
30 InsetMathMacro(InsetMathMacro const &);
32 InsetMathMacro & operator=(InsetMathMacro const &);
36 virtual InsetMathMacro * asMacro() { return this; }
38 virtual InsetMathMacro const * asMacro() const { return this; }
40 marker_type marker(BufferView const *) const;
41 /// If the macro is in normal edit mode, dissolve its contents in
42 /// the row. Otherwise, just insert the inset.
43 bool addToMathRow(MathRow &, MetricsInfo & mi) const;
45 /// Whether the inset allows \(no)limits
46 bool allowsLimitsChange() const;
47 /// The default limits value
48 Limits defaultLimits() const;
49 /// whether the inset has limit-like sub/superscript
50 Limits limits() const { return limits_; }
51 /// sets types of sub/superscripts
52 void limits(Limits lim) { limits_ = lim; }
55 void beforeMetrics() const;
57 void afterMetrics() const;
59 void beforeDraw(PainterInfo const &) const;
61 void afterDraw(PainterInfo const &) const;
64 void metrics(MetricsInfo & mi, Dimension & dim) const;
65 /// was the macro in edit mode when computing metrics?
66 bool editMetrics(BufferView const * bv) const;
68 void draw(PainterInfo & pi, int x, int y) const;
70 int kerning(BufferView const * bv) const;
71 /// get cursor position
72 void cursorPos(BufferView const & bv, CursorSlice const & sl,
73 bool boundary, int & x, int & y) const;
75 void edit(Cursor & cur, bool front, EntryDirection entry_from);
77 Inset * editXY(Cursor & cur, int x, int y);
79 /// target pos when we enter the inset while moving forward
80 bool idxFirst(Cursor &) const;
81 /// target pos when we enter the inset while moving backwards
82 bool idxLast(Cursor &) const;
85 virtual bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
87 /// Remove cell (starting from 0)
88 void removeArgument(pos_type pos);
89 /// Insert empty cell (starting from 0)
90 void insertArgument(pos_type pos);
93 void validate(LaTeXFeatures &) const;
95 mode_type currentMode() const;
97 /// Assumes that macros are up-to-date
98 void write(WriteStream & os) const;
100 void normalize(NormalStream & os) const;
102 void maple(MapleStream &) const;
104 void maxima(MaximaStream &) const;
106 void mathematica(MathematicaStream &) const;
108 void mathmlize(MathStream &) const;
110 void htmlize(HtmlStream &) const;
112 void octave(OctaveStream &) const;
114 void infoize(odocstream &) const;
116 void infoize2(odocstream &) const;
118 /// fold the macro in the next metrics call
119 void fold(Cursor & cur);
120 /// unfold the macro in the next metrics call
121 void unfold(Cursor & cur);
122 /// will it be folded or unfolded in the next metric call?
127 DISPLAY_INTERACTIVE_INIT,
133 DisplayMode displayMode() const;
136 bool extraBraces() const;
139 docstring name() const;
140 /// FIXME: Often dangling.
141 MacroData const * macro() const;
143 docstring macroName() const;
144 /// Level of nesting in macros (including this one)
147 bool validName() const;
149 size_t arity() const;
152 size_t optionals() const;
154 void setOptionals(int n);
155 /// Return the maximal number of arguments the macro is greedy for.
156 size_t appetite() const;
158 InsetCode lyxCode() const { return MATH_MACRO_CODE; }
159 /// This is not used for display; however whether it is mathrel determines
160 /// how to split equations intelligently.
161 MathClass mathClass() const; //override
162 /// Override so as to set Buffer for defnition_ member, too.
163 void setBuffer(Buffer &);
166 friend class MathData;
167 friend class ArgumentProxy;
170 /// update the display mode (should only be called after detaching arguments)
171 void setDisplayMode(DisplayMode mode, int appetite = -1);
172 /// compute the next display mode
173 DisplayMode computeDisplayMode() const;
174 /// update macro definition
175 void updateMacro(MacroContext const & mc);
176 /// check if macro definition changed, argument changed etc. and adapt
177 void updateRepresentation(Cursor * cur, MacroContext const & mc,
178 UpdateType, int nesting);
179 /// empty macro, put arguments into args, possibly strip arity-attachedArgsNum_ empty ones.
180 /// Includes the optional arguments.
181 void detachArguments(std::vector<MathData> & args, bool strip);
182 /// attach arguments (maybe less than arity at the end of an MathData),
183 /// including the optional ones (even if it can be empty here)
184 void attachArguments(std::vector<MathData> const & args, size_t arity, int optionals);
187 /// This function is needed for now because of two shortfalls of the current
188 /// implementation: the macro() pointer is often dangling, in which case we
189 /// fall back to a backup copy, and the macro is not known at inset
190 /// creation, in which case we fall back to the global macro with this name.
191 MacroData const * macroBackup() const;
193 virtual Inset * clone() const;
195 bool editMode(BufferView const * bv) const;
198 Limits limits_ = AUTO_LIMITS;
204 /// update lock to avoid loops
206 friend class UpdateLocker;
210 bool completionSupported(Cursor const &) const;
212 bool inlineCompletionSupported(Cursor const & cur) const;
214 bool automaticInlineCompletion() const;
216 bool automaticPopupCompletion() const;
218 CompletionList const * createCompletionList(Cursor const & cur) const;
220 docstring completionPrefix(Cursor const & cur) const;
222 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
224 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;