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