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