]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathNest.h
Fix footnote output in description item
[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 &);
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;
40         ///
41         void updateBuffer(ParIterator const &, UpdateType);
42         /// identifies NestInsets
43         InsetMathNest * asNestInset() { return this; }
44         /// identifies NestInsets
45         InsetMathNest const * asNestInset() const { return this; }
46         /// get cursor position
47         void cursorPos(BufferView const & bv, CursorSlice const & sl,
48                 bool boundary, int & x, int & y) const;
49         ///
50         void edit(Cursor & cur, bool front,
51                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
52         ///
53         Inset * editXY(Cursor & cur, int x, int y);
54
55         /// order of movement through the cells when moving backwards
56         bool idxBackward(Cursor &) const;
57         /// order of movement through the cells when moving forward
58         bool idxForward(Cursor &) const;
59
60         /// move to next cell
61         bool idxNext(Cursor &) const;
62         /// move to previous cell
63         bool idxPrev(Cursor &) const;
64
65         /// target pos when we enter the inset while moving forward
66         bool idxFirst(Cursor &) const;
67         /// target pos when we enter the inset while moving backwards
68         bool idxLast(Cursor &) const;
69
70         /// number of cells currently governed by us
71         idx_type nargs() const;
72         /// access to the lock
73         bool lock() const;
74         /// access to the lock
75         void lock(bool);
76         /// get notification when the cursor leaves this inset
77         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
78
79         //@{
80         /// direct access to the cell.
81         /// Inlined because of performance reasons.
82         MathData & cell(idx_type i) { return cells_[i]; }
83         MathData const & cell(idx_type i) const { return cells_[i]; }
84         //@}
85
86         /// can we move into this cell (see macroarg.h)
87         bool isActive() const;
88         /// request "external features"
89         void validate(LaTeXFeatures & features) const;
90
91         /// replace in all cells
92         void replace(ReplaceData &);
93         /// do we contain a given pattern?
94         bool contains(MathData const &) const;
95         /// glue everything to a single cell
96         MathData glue() const;
97
98         /// debug helper
99         void dump() const;
100
101         /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
102         void write(WriteStream & os) const;
103         /// writes [, name(), and args in []
104         void normalize(NormalStream & os) const;
105         ///
106         void latex(otexstream & os, OutputParams const & runparams) const;
107         ///
108         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
109         ///
110         bool mouseHovered(BufferView const * bv) const
111                 { return mouse_hover_[bv]; }
112
113         ///
114         bool completionSupported(Cursor const &) const;
115         ///
116         bool inlineCompletionSupported(Cursor const & cur) const;
117         ///
118         bool automaticInlineCompletion() const;
119         ///
120         bool automaticPopupCompletion() const;
121         ///
122         CompletionList const * createCompletionList(Cursor const & cur) const;
123         ///
124         docstring completionPrefix(Cursor const & cur) const;
125         ///
126         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
127         ///
128         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
129         ///
130         InsetCode lyxCode() const { return MATH_NEST_CODE; }
131
132         ///
133         bool confirmDeletion() const { return nargs() > 0; }
134
135 protected:
136         ///
137         InsetMathNest(InsetMathNest const & inset);
138         ///
139         InsetMathNest & operator=(InsetMathNest const &);
140
141         ///
142         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
143         /// do we want to handle this event?
144         bool getStatus(Cursor & cur, FuncRequest const & cmd,
145                 FuncStatus & status) const;
146         ///
147         void handleFont(Cursor & cur,
148                 docstring const & arg, docstring const & font);
149         void handleFont(Cursor & cur,
150                 docstring const & arg, char const * const font);
151         ///
152         void handleFont2(Cursor & cur, docstring const & arg);
153         /// Grab and erase selection and insert the InsetMathNest atom in every
154         /// previously selected cell, insert the grabbed former data and \c arg
155         /// in the first cell of the inserted atom.
156         void handleNest(Cursor & cur, MathAtom const & nest);
157         void handleNest(Cursor & cur, MathAtom const & nest, docstring const & arg);
158
159         /// interpret \p c and insert the result at the current position of
160         /// of \p cur. Return whether the cursor should stay in the formula.
161         bool interpretChar(Cursor & cur, char_type c);
162         ///
163         bool script(Cursor & cur, bool);
164         bool script(Cursor & cur, bool, docstring const & save_selection);
165
166 public:
167         /// interpret \p str and insert the result at the current position of
168         /// \p cur if it is something known. Return whether \p cur was
169         /// inserted.
170         virtual bool interpretString(Cursor & cur, docstring const & str);
171
172 private:
173         /// lfun handler
174         void lfunMousePress(Cursor &, FuncRequest &);
175         ///
176         void lfunMouseRelease(Cursor &, FuncRequest &);
177         ///
178         void lfunMouseMotion(Cursor &, FuncRequest &);
179         /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
180         /// afterwards if found
181         bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
182         /// move cursor forward
183         bool cursorMathForward(Cursor & cur, bool enter = true);
184         /// move cursor backwards
185         bool cursorMathBackward(Cursor & cur, bool enter = true);
186
187 protected:
188         /// we store the cells in a vector
189         typedef std::vector<MathData> cells_type;
190         /// thusly:
191         cells_type cells_;
192         /// if the inset is locked, it can't be entered with the cursor
193         bool lock_;
194         ///
195         mutable std::map<BufferView const *, bool> mouse_hover_;
196 };
197
198
199
200 } // namespace lyx
201 #endif