]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathNest.h
Rename InsetMathNest::metrics to cellsMetrics
[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 #include "MathData.h"
17
18 #include <map>
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         /// Update the cells metrics
37         void cellsMetrics(MetricsInfo const & mi) const;
38         /// draw background if locked
39         void draw(PainterInfo & pi, int x, int y) const;
40         /// draw selection background
41         void drawSelection(PainterInfo & pi, int x, int y) const;
42         ///
43         void updateBuffer(ParIterator const &, UpdateType);
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         //@{
82         /// direct access to the cell.
83         /// Inlined because of performance reasons.
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         void latex(otexstream & os, OutputParams const & runparams) const;
109         ///
110         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
111         ///
112         bool mouseHovered(BufferView const * bv) const 
113                 { return mouse_hover_[bv]; }
114
115         ///
116         bool completionSupported(Cursor const &) const;
117         ///
118         bool inlineCompletionSupported(Cursor const & cur) const;
119         ///
120         bool automaticInlineCompletion() const;
121         ///
122         bool automaticPopupCompletion() const;
123         ///
124         CompletionList const * createCompletionList(Cursor const & cur) const;
125         ///
126         docstring completionPrefix(Cursor const & cur) const;
127         ///
128         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
129         ///
130         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
131         ///
132         InsetCode lyxCode() const { return MATH_NEST_CODE; }
133
134 protected:
135         ///
136         InsetMathNest(InsetMathNest const & inset);
137         ///
138         InsetMathNest & operator=(InsetMathNest const &);
139
140         ///
141         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
142         /// do we want to handle this event?
143         bool getStatus(Cursor & cur, FuncRequest const & cmd,
144                 FuncStatus & status) const;
145         ///
146         void handleFont(Cursor & cur,
147                 docstring const & arg, docstring const & font);
148         void handleFont(Cursor & cur,
149                 docstring const & arg, char const * const font);
150         ///
151         void handleFont2(Cursor & cur, docstring const & arg);
152         /// Grab and erase selection and insert the InsetMathNest atom in every
153         /// previously selected cell, insert the grabbed former data and \c arg
154         /// in the first cell of the inserted atom.
155         void handleNest(Cursor & cur, MathAtom const & nest);
156         void handleNest(Cursor & cur, MathAtom const & nest, docstring const & arg);
157
158         /// interpret \p c and insert the result at the current position of
159         /// of \p cur. Return whether the cursor should stay in the formula.
160         bool interpretChar(Cursor & cur, char_type c);
161         ///
162         bool script(Cursor & cur, bool);
163         bool script(Cursor & cur, bool, docstring const & save_selection);
164
165 public:
166         /// interpret \p str and insert the result at the current position of
167         /// \p cur if it is something known. Return whether \p cur was
168         /// inserted.
169         virtual bool interpretString(Cursor & cur, docstring const & str);
170
171 private:
172         /// lfun handler
173         void lfunMousePress(Cursor &, FuncRequest &);
174         ///
175         void lfunMouseRelease(Cursor &, FuncRequest &);
176         ///
177         void lfunMouseMotion(Cursor &, FuncRequest &);
178         /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
179         /// afterwards if found
180         bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
181         /// move cursor forward
182         bool cursorMathForward(Cursor & cur, bool enter = true);
183         /// move cursor backwards
184         bool cursorMathBackward(Cursor & cur, bool enter = true);
185
186 protected:
187         /// we store the cells in a vector
188         typedef std::vector<MathData> cells_type;
189         /// thusly:
190         cells_type cells_;
191         /// if the inset is locked, it can't be entered with the cursor
192         bool lock_;
193         ///
194         mutable std::map<BufferView const *, bool> mouse_hover_;
195 };      
196
197
198
199 } // namespace lyx
200 #endif