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"
18 #include "support/docstring.h"
24 /** Abstract base class for all math objects that contain nested items.
25 This is basically everything that is not a single character or a
29 class InsetMathNest : public InsetMath {
31 /// nestinsets have a fixed size to start with
32 InsetMathNest(Buffer * buf, idx_type ncells);
34 virtual ~InsetMathNest();
36 void setBuffer(Buffer &);
38 /// the size is usually some sort of convex hull of the cells
39 /// hides inset::metrics() intentionally!
40 void metrics(MetricsInfo const & mi) const;
41 /// draw background if locked
42 void draw(PainterInfo & pi, int x, int y) const;
43 /// draw selection background
44 void drawSelection(PainterInfo & pi, int x, int y) const;
46 void drawDecoration(PainterInfo & pi, int x, int y) const
47 { drawMarkers(pi, x, y); }
49 void updateBuffer(ParIterator const &, UpdateType);
50 /// identifies NestInsets
51 InsetMathNest * asNestInset() { return this; }
52 /// identifies NestInsets
53 InsetMathNest const * asNestInset() const { return this; }
54 /// get cursor position
55 void cursorPos(BufferView const & bv, CursorSlice const & sl,
56 bool boundary, int & x, int & y) const;
58 void edit(Cursor & cur, bool front,
59 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
61 Inset * editXY(Cursor & cur, int x, int y);
63 /// order of movement through the cells when moving backwards
64 bool idxBackward(Cursor &) const;
65 /// order of movement through the cells when moving forward
66 bool idxForward(Cursor &) const;
69 bool idxNext(Cursor &) const;
70 /// move to previous cell
71 bool idxPrev(Cursor &) const;
73 /// target pos when we enter the inset while moving forward
74 bool idxFirst(Cursor &) const;
75 /// target pos when we enter the inset while moving backwards
76 bool idxLast(Cursor &) const;
78 /// number of cells currently governed by us
79 idx_type nargs() const;
80 /// access to the lock
82 /// access to the lock
84 /// get notification when the cursor leaves this inset
85 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
88 /// direct access to the cell.
89 /// Inlined because of performance reasons.
90 MathData & cell(idx_type i) { return cells_[i]; }
91 MathData const & cell(idx_type i) const { return cells_[i]; }
94 /// can we move into this cell (see macroarg.h)
95 bool isActive() const;
96 /// request "external features"
97 void validate(LaTeXFeatures & features) const;
99 /// replace in all cells
100 void replace(ReplaceData &);
101 /// do we contain a given pattern?
102 bool contains(MathData const &) const;
103 /// glue everything to a single cell
104 MathData glue() const;
109 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
110 void write(WriteStream & os) const;
111 /// writes [, name(), and args in []
112 void normalize(NormalStream & os) const;
114 void latex(otexstream & os, OutputParams const & runparams) const;
116 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
118 bool mouseHovered(BufferView const * bv) const
119 { return mouse_hover_[bv]; }
122 bool completionSupported(Cursor const &) const;
124 bool inlineCompletionSupported(Cursor const & cur) const;
126 bool automaticInlineCompletion() const;
128 bool automaticPopupCompletion() const;
130 CompletionList const * createCompletionList(Cursor const & cur) const;
132 docstring completionPrefix(Cursor const & cur) const;
134 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
136 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
138 InsetCode lyxCode() const { return MATH_NEST_CODE; }
142 InsetMathNest(InsetMathNest const & inset);
144 InsetMathNest & operator=(InsetMathNest const &);
147 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
148 /// do we want to handle this event?
149 bool getStatus(Cursor & cur, FuncRequest const & cmd,
150 FuncStatus & status) const;
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
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);
189 /// move cursor backwards
190 bool cursorMathBackward(Cursor & cur);
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_;