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(Buffer const &, odocstream & os,
132 OutputParams const & runparams) const;
134 bool setMouseHover(bool mouse_hover);
136 bool mouseHovered() const { return mouse_hover_; }
139 bool completionSupported(Cursor const &) const;
141 bool inlineCompletionSupported(Cursor const & cur) const;
143 bool automaticInlineCompletion() const;
145 bool automaticPopupCompletion() const;
147 CompletionList const * createCompletionList(Cursor const & cur) const;
149 docstring completionPrefix(Cursor const & cur) const;
151 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
153 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
157 InsetMathNest(InsetMathNest const & inset);
159 InsetMathNest & operator=(InsetMathNest const &);
162 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
163 /// do we want to handle this event?
164 bool getStatus(Cursor & cur, FuncRequest const & cmd,
165 FuncStatus & status) const;
167 void handleFont(Cursor & cur,
168 docstring const & arg, docstring const & font);
169 void handleFont(Cursor & cur,
170 docstring const & arg, char const * const font);
172 void handleFont2(Cursor & cur, docstring const & arg);
174 /// interpret \p c and insert the result at the current position of
175 /// of \p cur. Return whether the cursor should stay in the formula.
176 bool interpretChar(Cursor & cur, char_type c);
178 bool script(Cursor & cur, bool,
179 docstring const & save_selection = docstring());
182 /// interpret \p str and insert the result at the current position of
183 /// \p cur if it is something known. Return whether \p cur was
185 bool interpretString(Cursor & cur, docstring const & str);
189 void lfunMousePress(Cursor &, FuncRequest &);
191 void lfunMouseRelease(Cursor &, FuncRequest &);
193 void lfunMouseMotion(Cursor &, FuncRequest &);
194 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
195 /// afterwards if found
196 bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
197 /// move cursor forward
198 bool cursorMathForward(Cursor & cur);
199 /// move cursor backwards
200 bool cursorMathBackward(Cursor & cur);
203 /// we store the cells in a vector
204 typedef std::vector<MathData> cells_type;
207 /// if the inset is locked, it can't be entered with the cursor