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 /// If the macro is in normal edit mode, dissolve its contents in
41 /// the row. Otherwise, just insert the inset.
42 bool addToMathRow(MathRow &, MetricsInfo & mi) const;
44 void draw(PainterInfo & pi, int x, int y) const;
45 /// draw selection background
46 void drawSelection(PainterInfo & pi, int x, int y) const;
48 void drawDecoration(PainterInfo & pi, int x, int y) const
49 { drawMarkers2(pi, x, y); }
51 void metrics(MetricsInfo & mi, Dimension & dim) const;
52 /// was the macro in edit mode when computing metrics?
53 bool editMetrics(BufferView const * bv) const;
55 int kerning(BufferView const * bv) const;
56 /// get cursor position
57 void cursorPos(BufferView const & bv, CursorSlice const & sl,
58 bool boundary, int & x, int & y) const;
60 void edit(Cursor & cur, bool front, EntryDirection entry_from);
62 Inset * editXY(Cursor & cur, int x, int y);
64 /// target pos when we enter the inset while moving forward
65 bool idxFirst(Cursor &) const;
66 /// target pos when we enter the inset while moving backwards
67 bool idxLast(Cursor &) const;
70 virtual bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
72 /// Remove cell (starting from 0)
73 void removeArgument(pos_type pos);
74 /// Insert empty cell (starting from 0)
75 void insertArgument(pos_type pos);
78 void validate(LaTeXFeatures &) const;
80 mode_type currentMode() const;
83 void write(WriteStream & os) const;
85 void normalize(NormalStream & os) const;
87 void maple(MapleStream &) const;
89 void maxima(MaximaStream &) const;
91 void mathematica(MathematicaStream &) const;
93 void mathmlize(MathStream &) const;
95 void htmlize(HtmlStream &) const;
97 void octave(OctaveStream &) const;
99 void infoize(odocstream &) const;
101 void infoize2(odocstream &) const;
103 /// fold the macro in the next metrics call
104 void fold(Cursor & cur);
105 /// unfold the macro in the next metrics call
106 void unfold(Cursor & cur);
107 /// will it be folded or unfolded in the next metric call?
112 DISPLAY_INTERACTIVE_INIT,
118 DisplayMode displayMode() const;
121 bool extraBraces() const;
124 docstring name() const;
126 MacroData const * macro() const;
128 docstring macroName() const;
130 bool validName() const;
132 size_t arity() const;
135 size_t optionals() const;
137 void setOptionals(int n);
138 /// Return the maximal number of arguments the macro is greedy for.
139 size_t appetite() const;
141 InsetCode lyxCode() const { return MATH_MACRO_CODE; }
144 friend class MathData;
145 friend class ArgumentProxy;
148 /// update the display mode (should only be called after detaching arguments)
149 void setDisplayMode(DisplayMode mode, int appetite = -1);
150 /// compute the next display mode
151 DisplayMode computeDisplayMode() const;
152 /// update macro definition
153 void updateMacro(MacroContext const & mc);
154 /// check if macro definition changed, argument changed etc. and adapt
155 void updateRepresentation(Cursor * cur, MacroContext const & mc, UpdateType);
156 /// empty macro, put arguments into args, possibly strip arity-attachedArgsNum_ empty ones.
157 /// Includes the optional arguments.
158 void detachArguments(std::vector<MathData> & args, bool strip);
159 /// attach arguments (maybe less than arity at the end of an MathData),
160 /// including the optional ones (even if it can be empty here)
161 void attachArguments(std::vector<MathData> const & args, size_t arity, int optionals);
165 virtual Inset * clone() const;
167 bool editMode(BufferView const * bv) const;
173 /// update lock to avoid loops
175 friend class UpdateLocker;
179 bool completionSupported(Cursor const &) const;
181 bool inlineCompletionSupported(Cursor const & cur) const;
183 bool automaticInlineCompletion() const;
185 bool automaticPopupCompletion() const;
187 CompletionList const * createCompletionList(Cursor const & cur) const;
189 docstring completionPrefix(Cursor const & cur) const;
191 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
193 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;