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 bool sorted() const { return false; }
29 virtual size_t size() const;
31 virtual docstring const & 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;
45 /** Abstract base class for all math objects that contain nested items.
46 This is basically everything that is not a single character or a
50 class InsetMathNest : public InsetMath {
52 /// nestinsets have a fixed size to start with
53 explicit InsetMathNest(idx_type ncells);
55 virtual ~InsetMathNest() {}
57 /// the size is usually some sort of convex hull of the cells
58 /// hides inset::metrics() intentionally!
59 void metrics(MetricsInfo const & mi) const;
60 /// draw background if locked
61 void draw(PainterInfo & pi, int x, int y) const;
62 /// draw selection background
63 void drawSelection(PainterInfo & pi, int x, int y) const;
65 void drawDecoration(PainterInfo & pi, int x, int y) const
66 { drawMarkers(pi, x, y); }
67 /// identifies NestInsets
68 InsetMathNest * asNestInset() { return this; }
69 /// identifies NestInsets
70 InsetMathNest const * asNestInset() const { return this; }
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,
76 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
78 Inset * editXY(Cursor & cur, int x, int y);
80 /// order of movement through the cells when moving backwards
81 bool idxBackward(Cursor &) const;
82 /// order of movement through the cells when moving forward
83 bool idxForward(Cursor &) const;
86 bool idxNext(Cursor &) const;
87 /// move to previous cell
88 bool idxPrev(Cursor &) const;
90 /// target pos when we enter the inset while moving forward
91 bool idxFirst(Cursor &) const;
92 /// target pos when we enter the inset while moving backwards
93 bool idxLast(Cursor &) const;
95 /// number of cells currently governed by us
96 idx_type nargs() const;
97 /// access to the lock
99 /// access to the lock
101 /// get notification when the cursor leaves this inset
102 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
104 /// direct access to the cell.
105 /// inlined because shows in profile.
107 MathData & cell(idx_type i) { return cells_[i]; }
108 MathData const & cell(idx_type i) const { return cells_[i]; }
111 /// can we move into this cell (see macroarg.h)
112 bool isActive() const;
113 /// request "external features"
114 void validate(LaTeXFeatures & features) const;
116 /// replace in all cells
117 void replace(ReplaceData &);
118 /// do we contain a given pattern?
119 bool contains(MathData const &) const;
120 /// glue everything to a single cell
121 MathData glue() const;
126 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
127 void write(WriteStream & os) const;
128 /// writes [, name(), and args in []
129 void normalize(NormalStream & os) const;
131 int latex(odocstream & os, OutputParams const & runparams) const;
133 bool setMouseHover(bool mouse_hover);
135 bool mouseHovered() const { return mouse_hover_; }
138 bool completionSupported(Cursor const &) const;
140 bool inlineCompletionSupported(Cursor const & cur) const;
142 bool automaticInlineCompletion() const;
144 bool automaticPopupCompletion() const;
146 CompletionList const * createCompletionList(Cursor const & cur) const;
148 docstring completionPrefix(Cursor const & cur) const;
150 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
152 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
156 InsetMathNest(InsetMathNest const & inset);
158 InsetMathNest & operator=(InsetMathNest const &);
161 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
162 /// do we want to handle this event?
163 bool getStatus(Cursor & cur, FuncRequest const & cmd,
164 FuncStatus & status) const;
166 void handleFont(Cursor & cur,
167 docstring const & arg, docstring const & font);
168 void handleFont(Cursor & cur,
169 docstring const & arg, char const * const font);
171 void handleFont2(Cursor & cur, docstring const & arg);
173 /// interpret \p c and insert the result at the current position of
174 /// of \p cur. Return whether the cursor should stay in the formula.
175 bool interpretChar(Cursor & cur, char_type c);
177 bool script(Cursor & cur, bool,
178 docstring const & save_selection = docstring());
181 /// interpret \p str and insert the result at the current position of
182 /// \p cur if it is something known. Return whether \p cur was
184 bool interpretString(Cursor & cur, docstring const & str);
188 void lfunMousePress(Cursor &, FuncRequest &);
190 void lfunMouseRelease(Cursor &, FuncRequest &);
192 void lfunMouseMotion(Cursor &, FuncRequest &);
193 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
194 /// afterwards if found
195 bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
196 /// move cursor forward
197 bool cursorMathForward(Cursor & cur);
198 /// move cursor backwards
199 bool cursorMathBackward(Cursor & cur);
202 /// we store the cells in a vector
203 typedef std::vector<MathData> cells_type;
206 /// if the inset is locked, it can't be entered with the cursor