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"
22 /** Abstract base class for all math objects that contain nested items.
23 This is basically everything that is not a single character or a
27 class InsetMathNest : public InsetMath {
29 /// nestinsets have a fixed size to start with
30 InsetMathNest(Buffer * buf, idx_type ncells);
32 virtual ~InsetMathNest();
34 void setBuffer(Buffer &) override;
36 /// Update the cells metrics
37 void cellsMetrics(MetricsInfo const & mi) const;
38 /// draw background if locked
39 void draw(PainterInfo & pi, int x, int y) const override;
41 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
42 /// identifies NestInsets
43 InsetMathNest * asNestInset() override { return this; }
44 /// identifies NestInsets
45 InsetMathNest const * asNestInset() const override { return this; }
46 /// get cursor position
47 void cursorPos(BufferView const & bv, CursorSlice const & sl,
48 bool boundary, int & x, int & y) const override;
50 void edit(Cursor & cur, bool front,
51 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE) override;
53 Inset * editXY(Cursor & cur, int x, int y) override;
55 /// order of movement through the cells when moving backwards
56 bool idxBackward(Cursor &) const override;
57 /// order of movement through the cells when moving forward
58 bool idxForward(Cursor &) const override;
61 bool idxNext(Cursor &) const override;
62 /// move to previous cell
63 bool idxPrev(Cursor &) const override;
65 // The index of the cell entered while moving forward
66 virtual idx_type firstIdx() const { return 0; }
67 // The index of the cell entered while moving backward
68 virtual idx_type lastIdx() const { return nargs() - 1; }
70 /// target pos when we enter the inset while moving forward
71 bool idxFirst(Cursor &) const override;
72 /// target pos when we enter the inset while moving backwards
73 bool idxLast(Cursor &) const override;
75 /// number of cells currently governed by us
76 idx_type nargs() const override;
77 /// access to the lock
78 bool lock() const override;
79 /// access to the lock
80 void lock(bool) override;
81 /// get notification when the cursor leaves this inset
82 bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
85 /// direct access to the cell.
86 /// Inlined because of performance reasons.
87 MathData & cell(idx_type i) override { return cells_[i]; }
88 MathData const & cell(idx_type i) const override { return cells_[i]; }
91 /// can we move into this cell (see macroarg.h)
92 bool isActive() const override;
93 /// request "external features"
94 void validate(LaTeXFeatures & features) const override;
96 /// replace in all cells
97 void replace(ReplaceData &) override;
98 /// do we contain a given pattern?
99 bool contains(MathData const &) const override;
100 /// glue everything to a single cell
101 MathData glue() const;
104 void dump() const override;
106 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
107 void write(TeXMathStream & os) const override;
108 /// writes [, name(), and args in []
109 void normalize(NormalStream & os) const override;
111 void latex(otexstream & os, OutputParams const & runparams) const override;
113 bool setMouseHover(BufferView const * bv, bool mouse_hover) const override;
115 bool mouseHovered(BufferView const * bv) const override
116 { return mouse_hover_[bv]; }
119 bool completionSupported(Cursor const &) const override;
121 bool inlineCompletionSupported(Cursor const & cur) const override;
123 bool automaticInlineCompletion() const override;
125 bool automaticPopupCompletion() const override;
127 CompletionList const * createCompletionList(Cursor const & cur) const override;
129 docstring completionPrefix(Cursor const & cur) const override;
131 bool insertCompletion(Cursor & cur, docstring const & s, bool finished) override;
133 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const override;
135 InsetCode lyxCode() const override { return MATH_NEST_CODE; }
138 bool confirmDeletion() const override { return nargs() > 0; }
142 InsetMathNest(InsetMathNest const & inset);
144 InsetMathNest & operator=(InsetMathNest const &);
147 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
148 /// do we want to handle this event?
149 bool getStatus(Cursor & cur, FuncRequest const & cmd,
150 FuncStatus & status) const override;
152 void handleFont(Cursor & cur,
153 docstring const & arg, docstring const & font);
154 void handleFont(Cursor & cur,
155 docstring const & arg, char const * const font);
157 void handleFont2(Cursor & cur, docstring const & arg);
158 /// Grab and erase selection and insert the InsetMathNest atom in every
159 /// previously selected cell, insert the grabbed former data and \c arg
160 /// in the first cell of the inserted atom.
161 void handleNest(Cursor & cur, MathAtom const & nest);
162 void handleNest(Cursor & cur, MathAtom const & nest, docstring const & arg);
164 /// interpret \p c and insert the result at the current position of
165 /// of \p cur. Return whether the cursor should stay in the formula.
166 bool interpretChar(Cursor & cur, char_type c);
168 bool script(Cursor & cur, bool);
169 bool script(Cursor & cur, bool, docstring const & save_selection);
172 /// interpret \p str and insert the result at the current position of
173 /// \p cur if it is something known. Return whether \p cur was
174 /// inserted. Handles undo.
175 virtual bool interpretString(Cursor & cur, docstring const & str);
179 void lfunMousePress(Cursor &, FuncRequest &);
181 void lfunMouseRelease(Cursor &, FuncRequest &);
183 void lfunMouseMotion(Cursor &, FuncRequest &);
184 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
185 /// afterwards if found
186 bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
187 /// move cursor forward
188 bool cursorMathForward(Cursor & cur, bool enter = true);
189 /// move cursor backwards
190 bool cursorMathBackward(Cursor & cur, bool enter = true);
193 /// we store the cells in a vector
194 typedef std::vector<MathData> cells_type;
197 /// if the inset is locked, it can't be entered with the cursor
200 mutable std::map<BufferView const *, bool> mouse_hover_;