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"
21 class MathCompletionList : public Inset::CompletionList {
24 MathCompletionList(Cursor const & cur);
26 virtual ~MathCompletionList();
29 virtual size_t size() const;
31 virtual docstring data(size_t idx) const;
33 virtual std::string icon(size_t idx) const;
36 static void addToFavorites(docstring const & completion);
40 static std::vector<docstring> globals;
42 std::vector<docstring> locals;
44 static std::deque<docstring> favorites;
47 /** Abstract base class for all math objects that contain nested items.
48 This is basically everything that is not a single character or a
52 class InsetMathNest : public InsetMath {
54 /// nestinsets have a fixed size to start with
55 explicit InsetMathNest(idx_type ncells);
57 virtual ~InsetMathNest() {}
59 /// the size is usually some sort of convex hull of the cells
60 /// hides inset::metrics() intentionally!
61 void metrics(MetricsInfo const & mi) const;
62 /// draw background if locked
63 void draw(PainterInfo & pi, int x, int y) const;
64 /// draw selection background
65 void drawSelection(PainterInfo & pi, int x, int y) const;
67 void drawDecoration(PainterInfo & pi, int x, int y) const
68 { drawMarkers(pi, x, y); }
69 /// identifies NestInsets
70 InsetMathNest * asNestInset() { return this; }
71 /// identifies NestInsets
72 InsetMathNest const * asNestInset() const { return this; }
73 /// get cursor position
74 void cursorPos(BufferView const & bv, CursorSlice const & sl,
75 bool boundary, int & x, int & y) const;
77 void edit(Cursor & cur, bool front,
78 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
80 Inset * editXY(Cursor & cur, int x, int y);
82 /// order of movement through the cells when moving backwards
83 bool idxBackward(Cursor &) const;
84 /// order of movement through the cells when moving forward
85 bool idxForward(Cursor &) const;
88 bool idxNext(Cursor &) const;
89 /// move to previous cell
90 bool idxPrev(Cursor &) const;
92 /// target pos when we enter the inset while moving forward
93 bool idxFirst(Cursor &) const;
94 /// target pos when we enter the inset while moving backwards
95 bool idxLast(Cursor &) const;
97 /// number of cells currently governed by us
98 idx_type nargs() const;
99 /// access to the lock
101 /// access to the lock
103 /// get notification when the cursor leaves this inset
104 bool notifyCursorLeaves(Cursor & cur);
106 /// direct access to the cell.
107 /// inlined because shows in profile.
109 MathData & cell(idx_type i) { return cells_[i]; }
110 MathData const & cell(idx_type i) const { return cells_[i]; }
113 /// can we move into this cell (see macroarg.h)
114 bool isActive() const;
115 /// request "external features"
116 void validate(LaTeXFeatures & features) const;
118 /// replace in all cells
119 void replace(ReplaceData &);
120 /// do we contain a given pattern?
121 bool contains(MathData const &) const;
122 /// glue everything to a single cell
123 MathData glue() const;
128 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
129 void write(WriteStream & os) const;
130 /// writes [, name(), and args in []
131 void normalize(NormalStream & os) const;
133 int latex(Buffer const &, odocstream & os,
134 OutputParams const & runparams) const;
136 bool setMouseHover(bool mouse_hover);
138 bool mouseHovered() const { return mouse_hover_; }
141 bool completionSupported(Cursor const &) const;
143 bool inlineCompletionSupported(Cursor const & cur) const;
145 bool automaticInlineCompletion() const;
147 bool automaticPopupCompletion() const;
149 CompletionListPtr completionList(Cursor const & cur) const;
151 docstring completionPrefix(Cursor const & cur) const;
153 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
155 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
159 InsetMathNest(InsetMathNest const & inset);
161 InsetMathNest & operator=(InsetMathNest const &);
164 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
165 /// do we want to handle this event?
166 bool getStatus(Cursor & cur, FuncRequest const & cmd,
167 FuncStatus & status) const;
169 void handleFont(Cursor & cur,
170 docstring const & arg, docstring const & font);
171 void handleFont(Cursor & cur,
172 docstring const & arg, char const * const font);
174 void handleFont2(Cursor & cur, docstring const & arg);
176 /// interpret \p c and insert the result at the current position of
177 /// of \p cur. Return whether the cursor should stay in the formula.
178 bool interpretChar(Cursor & cur, char_type c);
180 bool script(Cursor & cur, bool,
181 docstring const & save_selection = docstring());
184 /// interpret \p str and insert the result at the current position of
185 /// \p cur if it is something known. Return whether \p cur was
187 bool interpretString(Cursor & cur, docstring const & str);
191 void lfunMousePress(Cursor &, FuncRequest &);
193 void lfunMouseRelease(Cursor &, FuncRequest &);
195 void lfunMouseMotion(Cursor &, FuncRequest &);
196 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
197 /// afterwards if found
198 bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
199 /// move cursor forward
200 bool cursorMathForward(Cursor & cur);
201 /// move cursor backwards
202 bool cursorMathBackward(Cursor & cur);
205 /// we store the cells in a vector
206 typedef std::vector<MathData> cells_type;
209 /// if the inset is locked, it can't be entered with the cursor