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 drawDecoration(PainterInfo & pi, int x, int y) const
53 { drawMarkers(pi, x, y); }
55 void updateBuffer(ParIterator const &, UpdateType);
56 /// identifies NestInsets
57 InsetMathNest * asNestInset() { return this; }
58 /// identifies NestInsets
59 InsetMathNest const * asNestInset() const { return this; }
60 /// get cursor position
61 void cursorPos(BufferView const & bv, CursorSlice const & sl,
62 bool boundary, int & x, int & y) const;
64 void edit(Cursor & cur, bool front,
65 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
67 Inset * editXY(Cursor & cur, int x, int y);
69 /// order of movement through the cells when moving backwards
70 bool idxBackward(Cursor &) const;
71 /// order of movement through the cells when moving forward
72 bool idxForward(Cursor &) const;
75 bool idxNext(Cursor &) const;
76 /// move to previous cell
77 bool idxPrev(Cursor &) const;
79 /// target pos when we enter the inset while moving forward
80 bool idxFirst(Cursor &) const;
81 /// target pos when we enter the inset while moving backwards
82 bool idxLast(Cursor &) const;
84 /// number of cells currently governed by us
85 idx_type nargs() const;
86 /// access to the lock
88 /// access to the lock
90 /// get notification when the cursor leaves this inset
91 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
94 /// direct access to the cell.
95 /// Inlined because of performance reasons.
96 MathData & cell(idx_type i) { return cells_[i]; }
97 MathData const & cell(idx_type i) const { return cells_[i]; }
100 /// can we move into this cell (see macroarg.h)
101 bool isActive() const;
102 /// request "external features"
103 void validate(LaTeXFeatures & features) const;
105 /// replace in all cells
106 void replace(ReplaceData &);
107 /// do we contain a given pattern?
108 bool contains(MathData const &) const;
109 /// glue everything to a single cell
110 MathData glue() const;
115 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
116 void write(WriteStream & os) const;
117 /// writes [, name(), and args in []
118 void normalize(NormalStream & os) const;
120 void latex(otexstream & os, OutputParams const & runparams) const;
122 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
124 bool mouseHovered(BufferView const * bv) const
125 { return mouse_hover_[bv]; }
128 bool completionSupported(Cursor const &) const;
130 bool inlineCompletionSupported(Cursor const & cur) const;
132 bool automaticInlineCompletion() const;
134 bool automaticPopupCompletion() const;
136 CompletionList const * createCompletionList(Cursor const & cur) const;
138 docstring completionPrefix(Cursor const & cur) const;
140 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
142 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
144 InsetCode lyxCode() const { return MATH_NEST_CODE; }
148 InsetMathNest(InsetMathNest const & inset);
150 InsetMathNest & operator=(InsetMathNest const &);
153 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
154 /// do we want to handle this event?
155 bool getStatus(Cursor & cur, FuncRequest const & cmd,
156 FuncStatus & status) const;
158 void handleFont(Cursor & cur,
159 docstring const & arg, docstring const & font);
160 void handleFont(Cursor & cur,
161 docstring const & arg, char const * const font);
163 void handleFont2(Cursor & cur, docstring const & arg);
164 /// Grab and erase selection and insert the InsetMathNest atom in every
165 /// previously selected cell, insert the grabbed former data and \c arg
166 /// in the first cell of the inserted atom.
167 void handleNest(Cursor & cur, MathAtom const & nest);
168 void handleNest(Cursor & cur, MathAtom const & nest, docstring const & arg);
170 /// interpret \p c and insert the result at the current position of
171 /// of \p cur. Return whether the cursor should stay in the formula.
172 bool interpretChar(Cursor & cur, char_type c);
174 bool script(Cursor & cur, bool);
175 bool script(Cursor & cur, bool, docstring const & save_selection);
178 /// interpret \p str and insert the result at the current position of
179 /// \p cur if it is something known. Return whether \p cur was
181 virtual bool interpretString(Cursor & cur, docstring const & str);
185 void lfunMousePress(Cursor &, FuncRequest &);
187 void lfunMouseRelease(Cursor &, FuncRequest &);
189 void lfunMouseMotion(Cursor &, FuncRequest &);
190 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
191 /// afterwards if found
192 bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
193 /// move cursor forward
194 bool cursorMathForward(Cursor & cur, bool enter = true);
195 /// move cursor backwards
196 bool cursorMathBackward(Cursor & cur, bool enter = true);
199 /// we store the cells in a vector
200 typedef std::vector<MathData> cells_type;
203 /// if the inset is locked, it can't be entered with the cursor
206 mutable std::map<BufferView const *, bool> mouse_hover_;