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"
21 /** Abstract base class for all math objects that contain nested items.
22 This is basically everything that is not a single character or a
26 class InsetMathNest : public InsetMath {
28 /// nestinsets have a fixed size to start with
29 InsetMathNest(Buffer * buf, idx_type ncells);
31 virtual ~InsetMathNest();
33 void setBuffer(Buffer &);
35 /// the size is usually some sort of convex hull of the cells
36 /// hides inset::metrics() intentionally!
37 void metrics(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 drawDecoration(PainterInfo & pi, int x, int y) const
44 { drawMarkers(pi, x, y); }
46 void updateBuffer(ParIterator const &, UpdateType);
47 /// identifies NestInsets
48 InsetMathNest * asNestInset() { return this; }
49 /// identifies NestInsets
50 InsetMathNest const * asNestInset() const { return this; }
51 /// get cursor position
52 void cursorPos(BufferView const & bv, CursorSlice const & sl,
53 bool boundary, int & x, int & y) const;
55 void edit(Cursor & cur, bool front,
56 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
58 Inset * editXY(Cursor & cur, int x, int y);
60 /// order of movement through the cells when moving backwards
61 bool idxBackward(Cursor &) const;
62 /// order of movement through the cells when moving forward
63 bool idxForward(Cursor &) const;
66 bool idxNext(Cursor &) const;
67 /// move to previous cell
68 bool idxPrev(Cursor &) const;
70 /// target pos when we enter the inset while moving forward
71 bool idxFirst(Cursor &) const;
72 /// target pos when we enter the inset while moving backwards
73 bool idxLast(Cursor &) const;
75 /// number of cells currently governed by us
76 idx_type nargs() const;
77 /// access to the lock
79 /// access to the lock
81 /// get notification when the cursor leaves this inset
82 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
85 /// direct access to the cell.
86 /// Inlined because of performance reasons.
87 MathData & cell(idx_type i) { return cells_[i]; }
88 MathData const & cell(idx_type i) const { return cells_[i]; }
91 /// can we move into this cell (see macroarg.h)
92 bool isActive() const;
93 /// request "external features"
94 void validate(LaTeXFeatures & features) const;
96 /// replace in all cells
97 void replace(ReplaceData &);
98 /// do we contain a given pattern?
99 bool contains(MathData const &) const;
100 /// glue everything to a single cell
101 MathData glue() const;
106 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
107 void write(WriteStream & os) const;
108 /// writes [, name(), and args in []
109 void normalize(NormalStream & os) const;
111 void latex(otexstream & os, OutputParams const & runparams) const;
113 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
115 bool mouseHovered(BufferView const * bv) const
116 { return mouse_hover_[bv]; }
119 bool completionSupported(Cursor const &) const;
121 bool inlineCompletionSupported(Cursor const & cur) const;
123 bool automaticInlineCompletion() const;
125 bool automaticPopupCompletion() const;
127 CompletionList const * createCompletionList(Cursor const & cur) const;
129 docstring completionPrefix(Cursor const & cur) const;
131 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
133 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
135 InsetCode lyxCode() const { return MATH_NEST_CODE; }
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);
186 /// move cursor backwards
187 bool cursorMathBackward(Cursor & cur);
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_;