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 MathMacro : public InsetMathNest {
27 /// A macro can be built from an existing template
28 MathMacro(Buffer * buf, docstring const & name);
30 MathMacro(MathMacro const &);
32 MathMacro & operator=(MathMacro const &);
36 virtual MathMacro * asMacro() { return this; }
38 virtual MathMacro const * asMacro() const { return this; }
40 void draw(PainterInfo & pi, int x, int y) const;
41 /// draw selection background
42 void drawSelection(PainterInfo & pi, int x, int y) const;
44 void drawDecoration(PainterInfo & pi, int x, int y) const
45 { drawMarkers2(pi, x, y); }
47 void metrics(MetricsInfo & mi, Dimension & dim) const;
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;
54 void edit(Cursor & cur, bool front, EntryDirection entry_from);
56 Inset * editXY(Cursor & cur, int x, int y);
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;
64 virtual bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
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);
72 void validate(LaTeXFeatures &) const;
74 mode_type currentMode() const;
77 void write(WriteStream & os) const;
79 void normalize(NormalStream & os) const;
81 void maple(MapleStream &) const;
83 void maxima(MaximaStream &) const;
85 void mathematica(MathematicaStream &) const;
87 void mathmlize(MathStream &) const;
89 void htmlize(HtmlStream &) const;
91 void octave(OctaveStream &) const;
93 void infoize(odocstream &) const;
95 void infoize2(odocstream &) const;
97 /// fold the macro in the next metrics call
98 void fold(Cursor & cur);
99 /// unfold the macro in the next metrics call
100 void unfold(Cursor & cur);
101 /// will it be folded or unfolded in the next metric call?
106 DISPLAY_INTERACTIVE_INIT,
112 DisplayMode displayMode() const;
115 bool extraBraces() const;
118 docstring name() const;
120 docstring macroName() const;
122 bool validName() const;
124 size_t arity() const;
127 size_t optionals() const;
129 void setOptionals(int n);
130 /// Return the maximal number of arguments the macro is greedy for.
131 size_t appetite() const;
133 InsetCode lyxCode() const { return MATH_MACRO_CODE; }
136 friend class MathData;
137 friend class ArgumentProxy;
140 /// update the display mode (should only be called after detaching arguments)
141 void setDisplayMode(DisplayMode mode, int appetite = -1);
142 /// compute the next display mode
143 DisplayMode computeDisplayMode() const;
144 /// update macro definition
145 void updateMacro(MacroContext const & mc);
146 /// check if macro definition changed, argument changed etc. and adapt
147 void updateRepresentation(Cursor * cur, MacroContext const & mc, UpdateType);
148 /// empty macro, put arguments into args, possibly strip arity-attachedArgsNum_ empty ones.
149 /// Includes the optional arguments.
150 void detachArguments(std::vector<MathData> & args, bool strip);
151 /// attach arguments (maybe less than arity at the end of an MathData),
152 /// including the optional ones (even if it can be empty here)
153 void attachArguments(std::vector<MathData> const & args, size_t arity, int optionals);
155 MacroData const * macro();
157 bool editMetrics(BufferView const * bv) const;
161 virtual Inset * clone() const;
163 bool editMode(BufferView const * bv) const;
169 /// update lock to avoid loops
171 friend class UpdateLocker;
175 bool completionSupported(Cursor const &) const;
177 bool inlineCompletionSupported(Cursor const & cur) const;
179 bool automaticInlineCompletion() const;
181 bool automaticPopupCompletion() const;
183 CompletionList const * createCompletionList(Cursor const & cur) const;
185 docstring completionPrefix(Cursor const & cur) const;
187 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
189 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;