]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathNest.h
Improve the list of equations
[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         // The method below hides inset::metrics() intentionally!
37         // We have to tell clang not to be fussy about that.
38 #ifdef __clang__
39 #pragma clang diagnostic push
40 #pragma clang diagnostic ignored "-Woverloaded-virtual"
41 #endif
42         /// the size is usually some sort of convex hull of the cells
43         void metrics(MetricsInfo const & mi) const;
44 #ifdef __clang__
45 #pragma clang diagnostic pop
46 #endif
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;
51         /// draw decorations.
52         void drawDecoration(PainterInfo & pi, int x, int y) const
53         { drawMarkers(pi, x, y); }
54         ///
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;
63         ///
64         void edit(Cursor & cur, bool front, 
65                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
66         ///
67         Inset * editXY(Cursor & cur, int x, int y);
68
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;
73
74         /// move to next cell
75         bool idxNext(Cursor &) const;
76         /// move to previous cell
77         bool idxPrev(Cursor &) const;
78
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;
83
84         /// number of cells currently governed by us
85         idx_type nargs() const;
86         /// access to the lock
87         bool lock() const;
88         /// access to the lock
89         void lock(bool);
90         /// get notification when the cursor leaves this inset
91         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
92
93         //@{
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]; }
98         //@}
99
100         /// can we move into this cell (see macroarg.h)
101         bool isActive() const;
102         /// request "external features"
103         void validate(LaTeXFeatures & features) const;
104
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;
111
112         /// debug helper
113         void dump() const;
114
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;
119         ///
120         void latex(otexstream & os, OutputParams const & runparams) const;
121         ///
122         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
123         ///
124         bool mouseHovered(BufferView const * bv) const 
125                 { return mouse_hover_[bv]; }
126
127         ///
128         bool completionSupported(Cursor const &) const;
129         ///
130         bool inlineCompletionSupported(Cursor const & cur) const;
131         ///
132         bool automaticInlineCompletion() const;
133         ///
134         bool automaticPopupCompletion() const;
135         ///
136         CompletionList const * createCompletionList(Cursor const & cur) const;
137         ///
138         docstring completionPrefix(Cursor const & cur) const;
139         ///
140         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
141         ///
142         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
143         ///
144         InsetCode lyxCode() const { return MATH_NEST_CODE; }
145
146 protected:
147         ///
148         InsetMathNest(InsetMathNest const & inset);
149         ///
150         InsetMathNest & operator=(InsetMathNest const &);
151
152         ///
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;
157         ///
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);
162         ///
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);
169
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);
173         ///
174         bool script(Cursor & cur, bool);
175         bool script(Cursor & cur, bool, docstring const & save_selection);
176
177 public:
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
180         /// inserted.
181         virtual bool interpretString(Cursor & cur, docstring const & str);
182
183 private:
184         /// lfun handler
185         void lfunMousePress(Cursor &, FuncRequest &);
186         ///
187         void lfunMouseRelease(Cursor &, FuncRequest &);
188         ///
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);
197
198 protected:
199         /// we store the cells in a vector
200         typedef std::vector<MathData> cells_type;
201         /// thusly:
202         cells_type cells_;
203         /// if the inset is locked, it can't be entered with the cursor
204         bool lock_;
205         ///
206         mutable std::map<BufferView const *, bool> mouse_hover_;
207 };      
208
209
210
211 } // namespace lyx
212 #endif