]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathNest.h
fab9f8d9ab8ee34e02b29404a2c40ca8d50491b0
[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 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(Buffer const &, odocstream & os,
132                         OutputParams const & runparams) const;
133         ///
134         bool setMouseHover(bool mouse_hover);
135         ///
136         bool mouseHovered() const { return mouse_hover_; }
137
138         ///
139         bool completionSupported(Cursor const &) const;
140         ///
141         bool inlineCompletionSupported(Cursor const & cur) const;
142         ///
143         bool automaticInlineCompletion() const;
144         ///
145         bool automaticPopupCompletion() const;
146         ///
147         CompletionList const * createCompletionList(Cursor const & cur) const;
148         ///
149         docstring completionPrefix(Cursor const & cur) const;
150         ///
151         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
152         ///
153         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
154
155 protected:
156         ///
157         InsetMathNest(InsetMathNest const & inset);
158         ///
159         InsetMathNest & operator=(InsetMathNest const &);
160
161         ///
162         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
163         /// do we want to handle this event?
164         bool getStatus(Cursor & cur, FuncRequest const & cmd,
165                 FuncStatus & status) const;
166         ///
167         void handleFont(Cursor & cur,
168                 docstring const & arg, docstring const & font);
169         void handleFont(Cursor & cur,
170                 docstring const & arg, char const * const font);
171         ///
172         void handleFont2(Cursor & cur, docstring const & arg);
173
174         /// interpret \p c and insert the result at the current position of
175         /// of \p cur. Return whether the cursor should stay in the formula.
176         bool interpretChar(Cursor & cur, char_type c);
177         ///
178         bool script(Cursor & cur, bool,
179                 docstring const & save_selection = docstring());
180
181 public:
182         /// interpret \p str and insert the result at the current position of
183         /// \p cur if it is something known. Return whether \p cur was
184         /// inserted.
185         bool interpretString(Cursor & cur, docstring const & str);
186
187 private:
188         /// lfun handler
189         void lfunMousePress(Cursor &, FuncRequest &);
190         ///
191         void lfunMouseRelease(Cursor &, FuncRequest &);
192         ///
193         void lfunMouseMotion(Cursor &, FuncRequest &);
194         /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
195         /// afterwards if found
196         bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
197         /// move cursor forward
198         bool cursorMathForward(Cursor & cur);
199         /// move cursor backwards
200         bool cursorMathBackward(Cursor & cur);
201
202 protected:
203         /// we store the cells in a vector
204         typedef std::vector<MathData> cells_type;
205         /// thusly:
206         cells_type cells_;
207         /// if the inset is locked, it can't be entered with the cursor
208         bool lock_;
209         ///
210         bool mouse_hover_;
211 };
212
213
214
215 } // namespace lyx
216 #endif