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