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