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