]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathNest.h
0a6579011ed7c0f550d8dc205be179bb7e78f1e3
[lyx.git] / src / mathed / InsetMathNest.h
1 // -*- C++ -*-
2 /**
3  * \file InsetMathNest.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef MATH_NESTINSET_H
13 #define MATH_NESTINSET_H
14
15 #include "InsetMath.h"
16 #include "MathData.h"
17
18 #include <map>
19
20 namespace lyx {
21
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
24     single symbol.
25 */
26
27 class InsetMathNest : public InsetMath {
28 public:
29         /// nestinsets have a fixed size to start with
30         InsetMathNest(Buffer * buf, idx_type ncells);
31         ///
32         virtual ~InsetMathNest();
33         ///
34         void setBuffer(Buffer &) override;
35
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 override;
40         ///
41         void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
42         /// identifies NestInsets
43         InsetMathNest * asNestInset() override { return this; }
44         /// identifies NestInsets
45         InsetMathNest const * asNestInset() const override { return this; }
46         /// get cursor position
47         void cursorPos(BufferView const & bv, CursorSlice const & sl,
48                 bool boundary, int & x, int & y) const override;
49         ///
50         void edit(Cursor & cur, bool front,
51                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE) override;
52         ///
53         Inset * editXY(Cursor & cur, int x, int y) override;
54
55         /// order of movement through the cells when moving backwards
56         bool idxBackward(Cursor &) const override;
57         /// order of movement through the cells when moving forward
58         bool idxForward(Cursor &) const override;
59
60         /// move to next cell
61         bool idxNext(Cursor &) const override;
62         /// move to previous cell
63         bool idxPrev(Cursor &) const override;
64
65         // The index of the cell entered while moving forward
66         virtual idx_type firstIdx() const { return 0; }
67         // The index of the cell entered while moving backward
68         virtual idx_type lastIdx() const { return nargs() - 1; }
69
70         /// target pos when we enter the inset while moving forward
71         bool idxFirst(Cursor &) const override;
72         /// target pos when we enter the inset while moving backwards
73         bool idxLast(Cursor &) const override;
74
75         /// number of cells currently governed by us
76         idx_type nargs() const override;
77         /// access to the lock
78         bool lock() const override;
79         /// access to the lock
80         void lock(bool) override;
81         /// get notification when the cursor leaves this inset
82         bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
83
84         //@{
85         /// direct access to the cell.
86         /// Inlined because of performance reasons.
87         MathData & cell(idx_type i) override { return cells_[i]; }
88         MathData const & cell(idx_type i) const override { return cells_[i]; }
89         //@}
90
91         /// can we move into this cell (see macroarg.h)
92         bool isActive() const override;
93         /// request "external features"
94         void validate(LaTeXFeatures & features) const override;
95
96         /// replace in all cells
97         void replace(ReplaceData &) override;
98         /// do we contain a given pattern?
99         bool contains(MathData const &) const override;
100         /// glue everything to a single cell
101         MathData glue() const;
102
103         /// debug helper
104         void dump() const override;
105
106         /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
107         void write(WriteStream & os) const override;
108         /// writes [, name(), and args in []
109         void normalize(NormalStream & os) const override;
110         ///
111         void latex(otexstream & os, OutputParams const & runparams) const override;
112         ///
113         bool setMouseHover(BufferView const * bv, bool mouse_hover) const override;
114         ///
115         bool mouseHovered(BufferView const * bv) const override
116                 { return mouse_hover_[bv]; }
117
118         ///
119         bool completionSupported(Cursor const &) const override;
120         ///
121         bool inlineCompletionSupported(Cursor const & cur) const override;
122         ///
123         bool automaticInlineCompletion() const override;
124         ///
125         bool automaticPopupCompletion() const override;
126         ///
127         CompletionList const * createCompletionList(Cursor const & cur) const override;
128         ///
129         docstring completionPrefix(Cursor const & cur) const override;
130         ///
131         bool insertCompletion(Cursor & cur, docstring const & s, bool finished) override;
132         ///
133         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const override;
134         ///
135         InsetCode lyxCode() const override { return MATH_NEST_CODE; }
136
137         ///
138         bool confirmDeletion() const override { return nargs() > 0; }
139
140 protected:
141         ///
142         InsetMathNest(InsetMathNest const & inset);
143         ///
144         InsetMathNest & operator=(InsetMathNest const &);
145
146         ///
147         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
148         /// do we want to handle this event?
149         bool getStatus(Cursor & cur, FuncRequest const & cmd,
150                 FuncStatus & status) const override;
151         ///
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);
156         ///
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);
163
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);
167         ///
168         bool script(Cursor & cur, bool);
169         bool script(Cursor & cur, bool, docstring const & save_selection);
170
171 public:
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
174         /// inserted. Handles undo.
175         virtual bool interpretString(Cursor & cur, docstring const & str);
176
177 private:
178         /// lfun handler
179         void lfunMousePress(Cursor &, FuncRequest &);
180         ///
181         void lfunMouseRelease(Cursor &, FuncRequest &);
182         ///
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, bool enter = true);
189         /// move cursor backwards
190         bool cursorMathBackward(Cursor & cur, bool enter = true);
191
192 protected:
193         /// we store the cells in a vector
194         typedef std::vector<MathData> cells_type;
195         /// thusly:
196         cells_type cells_;
197         /// if the inset is locked, it can't be entered with the cursor
198         bool lock_;
199         ///
200         mutable std::map<BufferView const *, bool> mouse_hover_;
201 };
202
203
204
205 } // namespace lyx
206 #endif