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