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