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 &);
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;
40 /// draw selection background
41 void drawSelection(PainterInfo & pi, int x, int y) const;
43 void updateBuffer(ParIterator const &, UpdateType);
44 /// identifies NestInsets
45 InsetMathNest * asNestInset() { return this; }
46 /// identifies NestInsets
47 InsetMathNest const * asNestInset() const { return this; }
48 /// get cursor position
49 void cursorPos(BufferView const & bv, CursorSlice const & sl,
50 bool boundary, int & x, int & y) const;
52 void edit(Cursor & cur, bool front,
53 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
55 Inset * editXY(Cursor & cur, int x, int y);
57 /// order of movement through the cells when moving backwards
58 bool idxBackward(Cursor &) const;
59 /// order of movement through the cells when moving forward
60 bool idxForward(Cursor &) const;
63 bool idxNext(Cursor &) const;
64 /// move to previous cell
65 bool idxPrev(Cursor &) const;
67 /// target pos when we enter the inset while moving forward
68 bool idxFirst(Cursor &) const;
69 /// target pos when we enter the inset while moving backwards
70 bool idxLast(Cursor &) const;
72 /// number of cells currently governed by us
73 idx_type nargs() const;
74 /// access to the lock
76 /// access to the lock
78 /// get notification when the cursor leaves this inset
79 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
82 /// direct access to the cell.
83 /// Inlined because of performance reasons.
84 MathData & cell(idx_type i) { return cells_[i]; }
85 MathData const & cell(idx_type i) const { return cells_[i]; }
88 /// can we move into this cell (see macroarg.h)
89 bool isActive() const;
90 /// request "external features"
91 void validate(LaTeXFeatures & features) const;
93 /// replace in all cells
94 void replace(ReplaceData &);
95 /// do we contain a given pattern?
96 bool contains(MathData const &) const;
97 /// glue everything to a single cell
98 MathData glue() const;
103 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
104 void write(WriteStream & os) const;
105 /// writes [, name(), and args in []
106 void normalize(NormalStream & os) const;
108 void latex(otexstream & os, OutputParams const & runparams) const;
110 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
112 bool mouseHovered(BufferView const * bv) const
113 { return mouse_hover_[bv]; }
116 bool completionSupported(Cursor const &) const;
118 bool inlineCompletionSupported(Cursor const & cur) const;
120 bool automaticInlineCompletion() const;
122 bool automaticPopupCompletion() const;
124 CompletionList const * createCompletionList(Cursor const & cur) const;
126 docstring completionPrefix(Cursor const & cur) const;
128 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
130 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
132 InsetCode lyxCode() const { return MATH_NEST_CODE; }
135 bool confirmDeletion() const { return nargs() > 0; }
139 InsetMathNest(InsetMathNest const & inset);
141 InsetMathNest & operator=(InsetMathNest const &);
144 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
145 /// do we want to handle this event?
146 bool getStatus(Cursor & cur, FuncRequest const & cmd,
147 FuncStatus & status) const;
149 void handleFont(Cursor & cur,
150 docstring const & arg, docstring const & font);
151 void handleFont(Cursor & cur,
152 docstring const & arg, char const * const font);
154 void handleFont2(Cursor & cur, docstring const & arg);
155 /// Grab and erase selection and insert the InsetMathNest atom in every
156 /// previously selected cell, insert the grabbed former data and \c arg
157 /// in the first cell of the inserted atom.
158 void handleNest(Cursor & cur, MathAtom const & nest);
159 void handleNest(Cursor & cur, MathAtom const & nest, docstring const & arg);
161 /// interpret \p c and insert the result at the current position of
162 /// of \p cur. Return whether the cursor should stay in the formula.
163 bool interpretChar(Cursor & cur, char_type c);
165 bool script(Cursor & cur, bool);
166 bool script(Cursor & cur, bool, docstring const & save_selection);
169 /// interpret \p str and insert the result at the current position of
170 /// \p cur if it is something known. Return whether \p cur was
172 virtual bool interpretString(Cursor & cur, docstring const & str);
176 void lfunMousePress(Cursor &, FuncRequest &);
178 void lfunMouseRelease(Cursor &, FuncRequest &);
180 void lfunMouseMotion(Cursor &, FuncRequest &);
181 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
182 /// afterwards if found
183 bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
184 /// move cursor forward
185 bool cursorMathForward(Cursor & cur, bool enter = true);
186 /// move cursor backwards
187 bool cursorMathBackward(Cursor & cur, bool enter = true);
190 /// we store the cells in a vector
191 typedef std::vector<MathData> cells_type;
194 /// if the inset is locked, it can't be entered with the cursor
197 mutable std::map<BufferView const *, bool> mouse_hover_;