]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathNest.h
31f12c21c145ce91b282e23b537c2beaacc312c6
[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         ///
37         Dimension const dimension(BufferView const &) const { return dim_; };
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         /// draw decorations.
43         void drawDecoration(PainterInfo & pi, int x, int y) const
44         { drawMarkers(pi, x, y); }
45         /// identifies NestInsets
46         InsetMathNest * asNestInset() { return this; }
47         /// identifies NestInsets
48         InsetMathNest const * asNestInset() const { return this; }
49         /// get cursor position
50         void cursorPos(BufferView const & bv, CursorSlice const & sl,
51                 bool boundary, int & x, int & y) const;
52         ///
53         void edit(Cursor & cur, bool left);
54         ///
55         Inset * editXY(Cursor & cur, int x, int y);
56
57         /// order of movement through the cells when pressing the left key
58         bool idxLeft(Cursor &) const;
59         /// order of movement through the cells when pressing the right key
60         bool idxRight(Cursor &) const;
61
62         /// move one physical cell up
63         bool idxNext(Cursor &) const;
64         /// move one physical cell down
65         bool idxPrev(Cursor &) const;
66
67         /// target pos when we enter the inset from the left by pressing "Right"
68         bool idxFirst(Cursor &) const;
69         /// target pos when we enter the inset from the right by pressing "Left"
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 & cur);
80
81         /// direct access to the cell.
82         /// inlined because shows in profile.
83         //@{
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         int latex(Buffer const &, odocstream & os,
109                         OutputParams const & runparams) const;
110         ///
111         bool setMouseHover(bool mouse_hover);
112         ///
113         bool mouseHovered() const { return mouse_hover_; }
114
115 protected:
116         ///
117         InsetMathNest(InsetMathNest const & inset);
118         ///
119         InsetMathNest & operator=(InsetMathNest const &);
120
121         ///
122         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
123         /// do we want to handle this event?
124         bool getStatus(Cursor & cur, FuncRequest const & cmd,
125                 FuncStatus & status) const;
126         ///
127         void handleFont(Cursor & cur,
128                 docstring const & arg, docstring const & font);
129         void handleFont(Cursor & cur,
130                 docstring const & arg, char const * const font);
131         ///
132         void handleFont2(Cursor & cur, docstring const & arg);
133
134         /// interpret \p c and insert the result at the current position of
135         /// of \p cur. Return whether the cursor should stay in the formula.
136         bool interpretChar(Cursor & cur, char_type c);
137         ///
138         bool script(Cursor & cur, bool,
139                 docstring const & save_selection = docstring());
140
141 public:
142         /// interpret \p str and insert the result at the current position of
143         /// \p cur if it is something known. Return whether \p cur was
144         /// inserted.
145         bool interpretString(Cursor & cur, docstring const & str);
146
147 private:
148         /// lfun handler
149         void lfunMousePress(Cursor &, FuncRequest &);
150         ///
151         void lfunMouseRelease(Cursor &, FuncRequest &);
152         ///
153         void lfunMouseMotion(Cursor &, FuncRequest &);
154
155 protected:
156         /// we store the cells in a vector
157         typedef std::vector<MathData> cells_type;
158         /// thusly:
159         cells_type cells_;
160         /// if the inset is locked, it can't be entered with the cursor
161         bool lock_;
162         ///
163         bool mouse_hover_;
164         /// Cached dimensions of the inset.
165         mutable Dimension dim_;
166 };
167
168
169
170 } // namespace lyx
171 #endif