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