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