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