3 * \file InsetMathNest.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef MATH_NESTINSET_H
13 #define MATH_NESTINSET_H
15 #include "InsetMath.h"
19 class MathCompletionList : public Inset::CompletionList {
22 MathCompletionList(Cursor const & cur);
24 virtual ~MathCompletionList();
27 virtual size_t size() const;
29 virtual docstring data(size_t idx) const;
31 virtual std::string icon(size_t idx) const;
34 static void addToFavorites(docstring const & completion);
38 static std::vector<docstring> globals;
40 std::vector<docstring> locals;
43 /** Abstract base class for all math objects that contain nested items.
44 This is basically everything that is not a single character or a
48 class InsetMathNest : public InsetMath {
50 /// nestinsets have a fixed size to start with
51 explicit InsetMathNest(idx_type ncells);
53 virtual ~InsetMathNest() {}
55 /// the size is usually some sort of convex hull of the cells
56 /// hides inset::metrics() intentionally!
57 void metrics(MetricsInfo const & mi) const;
58 /// draw background if locked
59 void draw(PainterInfo & pi, int x, int y) const;
60 /// draw selection background
61 void drawSelection(PainterInfo & pi, int x, int y) const;
63 void drawDecoration(PainterInfo & pi, int x, int y) const
64 { drawMarkers(pi, x, y); }
65 /// identifies NestInsets
66 InsetMathNest * asNestInset() { return this; }
67 /// identifies NestInsets
68 InsetMathNest const * asNestInset() const { return this; }
69 /// get cursor position
70 void cursorPos(BufferView const & bv, CursorSlice const & sl,
71 bool boundary, int & x, int & y) const;
73 void edit(Cursor & cur, bool front,
74 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
76 Inset * editXY(Cursor & cur, int x, int y);
78 /// order of movement through the cells when moving backwards
79 bool idxBackward(Cursor &) const;
80 /// order of movement through the cells when moving forward
81 bool idxForward(Cursor &) const;
84 bool idxNext(Cursor &) const;
85 /// move to previous cell
86 bool idxPrev(Cursor &) const;
88 /// target pos when we enter the inset while moving forward
89 bool idxFirst(Cursor &) const;
90 /// target pos when we enter the inset while moving backwards
91 bool idxLast(Cursor &) const;
93 /// number of cells currently governed by us
94 idx_type nargs() const;
95 /// access to the lock
97 /// access to the lock
99 /// get notification when the cursor leaves this inset
100 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
102 /// direct access to the cell.
103 /// inlined because shows in profile.
105 MathData & cell(idx_type i) { return cells_[i]; }
106 MathData const & cell(idx_type i) const { return cells_[i]; }
109 /// can we move into this cell (see macroarg.h)
110 bool isActive() const;
111 /// request "external features"
112 void validate(LaTeXFeatures & features) const;
114 /// replace in all cells
115 void replace(ReplaceData &);
116 /// do we contain a given pattern?
117 bool contains(MathData const &) const;
118 /// glue everything to a single cell
119 MathData glue() const;
124 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
125 void write(WriteStream & os) const;
126 /// writes [, name(), and args in []
127 void normalize(NormalStream & os) const;
129 int latex(Buffer const &, odocstream & os,
130 OutputParams const & runparams) const;
132 bool setMouseHover(bool mouse_hover);
134 bool mouseHovered() const { return mouse_hover_; }
137 bool completionSupported(Cursor const &) const;
139 bool inlineCompletionSupported(Cursor const & cur) const;
141 bool automaticInlineCompletion() const;
143 bool automaticPopupCompletion() const;
145 CompletionList const * createCompletionList(Cursor const & cur) const;
147 docstring completionPrefix(Cursor const & cur) const;
149 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
151 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
155 InsetMathNest(InsetMathNest const & inset);
157 InsetMathNest & operator=(InsetMathNest const &);
160 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
161 /// do we want to handle this event?
162 bool getStatus(Cursor & cur, FuncRequest const & cmd,
163 FuncStatus & status) const;
165 void handleFont(Cursor & cur,
166 docstring const & arg, docstring const & font);
167 void handleFont(Cursor & cur,
168 docstring const & arg, char const * const font);
170 void handleFont2(Cursor & cur, docstring const & arg);
172 /// interpret \p c and insert the result at the current position of
173 /// of \p cur. Return whether the cursor should stay in the formula.
174 bool interpretChar(Cursor & cur, char_type c);
176 bool script(Cursor & cur, bool,
177 docstring const & save_selection = docstring());
180 /// interpret \p str and insert the result at the current position of
181 /// \p cur if it is something known. Return whether \p cur was
183 bool interpretString(Cursor & cur, docstring const & str);
187 void lfunMousePress(Cursor &, FuncRequest &);
189 void lfunMouseRelease(Cursor &, FuncRequest &);
191 void lfunMouseMotion(Cursor &, FuncRequest &);
192 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
193 /// afterwards if found
194 bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
195 /// move cursor forward
196 bool cursorMathForward(Cursor & cur);
197 /// move cursor backwards
198 bool cursorMathBackward(Cursor & cur);
201 /// we store the cells in a vector
202 typedef std::vector<MathData> cells_type;
205 /// if the inset is locked, it can't be entered with the cursor