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 // The method below hides inset::metrics() intentionally!
37 // We have to tell clang not to be fussy about that.
39 #pragma clang diagnostic push
40 #pragma clang diagnostic ignored "-Woverloaded-virtual"
42 /// the size is usually some sort of convex hull of the cells
43 void metrics(MetricsInfo const & mi) const;
45 #pragma clang diagnostic pop
47 /// draw background if locked
48 void draw(PainterInfo & pi, int x, int y) const;
49 /// draw selection background
50 void drawSelection(PainterInfo & pi, int x, int y) const;
52 void updateBuffer(ParIterator const &, UpdateType);
53 /// identifies NestInsets
54 InsetMathNest * asNestInset() { return this; }
55 /// identifies NestInsets
56 InsetMathNest const * asNestInset() const { return this; }
57 /// get cursor position
58 void cursorPos(BufferView const & bv, CursorSlice const & sl,
59 bool boundary, int & x, int & y) const;
61 void edit(Cursor & cur, bool front,
62 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
64 Inset * editXY(Cursor & cur, int x, int y);
66 /// order of movement through the cells when moving backwards
67 bool idxBackward(Cursor &) const;
68 /// order of movement through the cells when moving forward
69 bool idxForward(Cursor &) const;
72 bool idxNext(Cursor &) const;
73 /// move to previous cell
74 bool idxPrev(Cursor &) const;
76 /// target pos when we enter the inset while moving forward
77 bool idxFirst(Cursor &) const;
78 /// target pos when we enter the inset while moving backwards
79 bool idxLast(Cursor &) const;
81 /// number of cells currently governed by us
82 idx_type nargs() const;
83 /// access to the lock
85 /// access to the lock
87 /// get notification when the cursor leaves this inset
88 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
91 /// direct access to the cell.
92 /// Inlined because of performance reasons.
93 MathData & cell(idx_type i) { return cells_[i]; }
94 MathData const & cell(idx_type i) const { return cells_[i]; }
97 /// can we move into this cell (see macroarg.h)
98 bool isActive() const;
99 /// request "external features"
100 void validate(LaTeXFeatures & features) const;
102 /// replace in all cells
103 void replace(ReplaceData &);
104 /// do we contain a given pattern?
105 bool contains(MathData const &) const;
106 /// glue everything to a single cell
107 MathData glue() const;
112 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
113 void write(WriteStream & os) const;
114 /// writes [, name(), and args in []
115 void normalize(NormalStream & os) const;
117 void latex(otexstream & os, OutputParams const & runparams) const;
119 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
121 bool mouseHovered(BufferView const * bv) const
122 { return mouse_hover_[bv]; }
125 bool completionSupported(Cursor const &) const;
127 bool inlineCompletionSupported(Cursor const & cur) const;
129 bool automaticInlineCompletion() const;
131 bool automaticPopupCompletion() const;
133 CompletionList const * createCompletionList(Cursor const & cur) const;
135 docstring completionPrefix(Cursor const & cur) const;
137 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
139 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
141 InsetCode lyxCode() const { return MATH_NEST_CODE; }
145 InsetMathNest(InsetMathNest const & inset);
147 InsetMathNest & operator=(InsetMathNest const &);
150 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
151 /// do we want to handle this event?
152 bool getStatus(Cursor & cur, FuncRequest const & cmd,
153 FuncStatus & status) const;
155 void handleFont(Cursor & cur,
156 docstring const & arg, docstring const & font);
157 void handleFont(Cursor & cur,
158 docstring const & arg, char const * const font);
160 void handleFont2(Cursor & cur, docstring const & arg);
161 /// Grab and erase selection and insert the InsetMathNest atom in every
162 /// previously selected cell, insert the grabbed former data and \c arg
163 /// in the first cell of the inserted atom.
164 void handleNest(Cursor & cur, MathAtom const & nest);
165 void handleNest(Cursor & cur, MathAtom const & nest, docstring const & arg);
167 /// interpret \p c and insert the result at the current position of
168 /// of \p cur. Return whether the cursor should stay in the formula.
169 bool interpretChar(Cursor & cur, char_type c);
171 bool script(Cursor & cur, bool);
172 bool script(Cursor & cur, bool, docstring const & save_selection);
175 /// interpret \p str and insert the result at the current position of
176 /// \p cur if it is something known. Return whether \p cur was
178 virtual bool interpretString(Cursor & cur, docstring const & str);
182 void lfunMousePress(Cursor &, FuncRequest &);
184 void lfunMouseRelease(Cursor &, FuncRequest &);
186 void lfunMouseMotion(Cursor &, FuncRequest &);
187 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
188 /// afterwards if found
189 bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
190 /// move cursor forward
191 bool cursorMathForward(Cursor & cur, bool enter = true);
192 /// move cursor backwards
193 bool cursorMathBackward(Cursor & cur, bool enter = true);
196 /// we store the cells in a vector
197 typedef std::vector<MathData> cells_type;
200 /// if the inset is locked, it can't be entered with the cursor
203 mutable std::map<BufferView const *, bool> mouse_hover_;