]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathNest.h
3d990b273921b63d579d9995f6e98be4b2cb5dbc
[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
17 #include <deque>
18
19 namespace lyx {
20
21 class MathCompletionList : public Inset::CompletionList {
22 public:
23         ///
24         MathCompletionList(Cursor const & cur);
25         ///
26         virtual ~MathCompletionList();
27
28         ///
29         virtual size_t size() const;
30         ///
31         virtual docstring data(size_t idx) const;
32         ///
33         virtual std::string icon(size_t idx) const;
34
35         ///
36         static void addToFavorites(docstring const & completion);
37
38 private:
39         ///
40         static std::vector<docstring> globals;
41         ///
42         std::vector<docstring> locals;
43         ///
44         static std::deque<docstring> favorites;
45 };
46
47 /** Abstract base class for all math objects that contain nested items.
48     This is basically everything that is not a single character or a
49     single symbol.
50 */
51
52 class InsetMathNest : public InsetMath {
53 public:
54         /// nestinsets have a fixed size to start with
55         explicit InsetMathNest(idx_type ncells);
56         ///
57         virtual ~InsetMathNest() {}
58
59         /// the size is usually some sort of convex hull of the cells
60         /// hides inset::metrics() intentionally!
61         void metrics(MetricsInfo const & mi) const;
62         /// draw background if locked
63         void draw(PainterInfo & pi, int x, int y) const;
64         /// draw selection background
65         void drawSelection(PainterInfo & pi, int x, int y) const;
66         /// draw decorations.
67         void drawDecoration(PainterInfo & pi, int x, int y) const
68         { drawMarkers(pi, x, y); }
69         /// identifies NestInsets
70         InsetMathNest * asNestInset() { return this; }
71         /// identifies NestInsets
72         InsetMathNest const * asNestInset() const { return this; }
73         /// get cursor position
74         void cursorPos(BufferView const & bv, CursorSlice const & sl,
75                 bool boundary, int & x, int & y) const;
76         ///
77         void edit(Cursor & cur, bool front, 
78                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
79         ///
80         Inset * editXY(Cursor & cur, int x, int y);
81
82         /// order of movement through the cells when moving backwards
83         bool idxBackward(Cursor &) const;
84         /// order of movement through the cells when moving forward
85         bool idxForward(Cursor &) const;
86
87         /// move to next cell
88         bool idxNext(Cursor &) const;
89         /// move to previous cell
90         bool idxPrev(Cursor &) const;
91
92         /// target pos when we enter the inset while moving forward
93         bool idxFirst(Cursor &) const;
94         /// target pos when we enter the inset while moving backwards
95         bool idxLast(Cursor &) const;
96
97         /// number of cells currently governed by us
98         idx_type nargs() const;
99         /// access to the lock
100         bool lock() const;
101         /// access to the lock
102         void lock(bool);
103         /// get notification when the cursor leaves this inset
104         bool notifyCursorLeaves(Cursor & cur);
105
106         /// direct access to the cell.
107         /// inlined because shows in profile.
108         //@{
109         MathData & cell(idx_type i) { return cells_[i]; }
110         MathData const & cell(idx_type i) const { return cells_[i]; }
111         //@}
112
113         /// can we move into this cell (see macroarg.h)
114         bool isActive() const;
115         /// request "external features"
116         void validate(LaTeXFeatures & features) const;
117
118         /// replace in all cells
119         void replace(ReplaceData &);
120         /// do we contain a given pattern?
121         bool contains(MathData const &) const;
122         /// glue everything to a single cell
123         MathData glue() const;
124
125         /// debug helper
126         void dump() const;
127
128         /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
129         void write(WriteStream & os) const;
130         /// writes [, name(), and args in []
131         void normalize(NormalStream & os) const;
132         ///
133         int latex(Buffer const &, odocstream & os,
134                         OutputParams const & runparams) const;
135         ///
136         bool setMouseHover(bool mouse_hover);
137         ///
138         bool mouseHovered() const { return mouse_hover_; }
139
140         ///
141         bool completionSupported(Cursor const &) const;
142         ///
143         bool inlineCompletionSupported(Cursor const & cur) const;
144         ///
145         bool automaticInlineCompletion() const;
146         ///
147         bool automaticPopupCompletion() const;
148         ///
149         CompletionListPtr completionList(Cursor const & cur) const;
150         ///
151         docstring completionPrefix(Cursor const & cur) const;
152         ///
153         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
154         ///
155         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
156
157 protected:
158         ///
159         InsetMathNest(InsetMathNest const & inset);
160         ///
161         InsetMathNest & operator=(InsetMathNest const &);
162
163         ///
164         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
165         /// do we want to handle this event?
166         bool getStatus(Cursor & cur, FuncRequest const & cmd,
167                 FuncStatus & status) const;
168         ///
169         void handleFont(Cursor & cur,
170                 docstring const & arg, docstring const & font);
171         void handleFont(Cursor & cur,
172                 docstring const & arg, char const * const font);
173         ///
174         void handleFont2(Cursor & cur, docstring const & arg);
175
176         /// interpret \p c and insert the result at the current position of
177         /// of \p cur. Return whether the cursor should stay in the formula.
178         bool interpretChar(Cursor & cur, char_type c);
179         ///
180         bool script(Cursor & cur, bool,
181                 docstring const & save_selection = docstring());
182
183 public:
184         /// interpret \p str and insert the result at the current position of
185         /// \p cur if it is something known. Return whether \p cur was
186         /// inserted.
187         bool interpretString(Cursor & cur, docstring const & str);
188
189 private:
190         /// lfun handler
191         void lfunMousePress(Cursor &, FuncRequest &);
192         ///
193         void lfunMouseRelease(Cursor &, FuncRequest &);
194         ///
195         void lfunMouseMotion(Cursor &, FuncRequest &);
196         /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
197         /// afterwards if found
198         bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
199         /// move cursor forward
200         bool cursorMathForward(Cursor & cur);
201         /// move cursor backwards
202         bool cursorMathBackward(Cursor & cur);
203
204 protected:
205         /// we store the cells in a vector
206         typedef std::vector<MathData> cells_type;
207         /// thusly:
208         cells_type cells_;
209         /// if the inset is locked, it can't be entered with the cursor
210         bool lock_;
211         ///
212         bool mouse_hover_;
213 };
214
215
216
217 } // namespace lyx
218 #endif