]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathNest.h
c204dbd09b884eef21d2c4c6fc0927133a954f39
[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() { destroyed(); }
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 left);
52         ///
53         Inset * editXY(Cursor & cur, int x, int y);
54
55         /// order of movement through the cells when pressing the left key
56         bool idxLeft(Cursor &) const;
57         /// order of movement through the cells when pressing the right key
58         bool idxRight(Cursor &) const;
59
60         /// move one physical cell up
61         bool idxNext(Cursor &) const;
62         /// move one physical cell down
63         bool idxPrev(Cursor &) const;
64
65         /// target pos when we enter the inset from the left by pressing "Right"
66         bool idxFirst(Cursor &) const;
67         /// target pos when we enter the inset from the right by pressing "Left"
68         bool idxLast(Cursor &) const;
69
70         /// number of cells currently governed by us
71         idx_type nargs() const;
72         /// access to the lock
73         bool lock() const;
74         /// access to the lock
75         void lock(bool);
76         /// get notification when the cursor leaves this inset
77         bool notifyCursorLeaves(Cursor & cur);
78
79         /// direct access to the cell.
80         /// inlined because shows in profile.
81         //@{
82         MathData & cell(idx_type i) { return cells_[i]; }
83         MathData const & cell(idx_type i) const { return cells_[i]; }
84         //@}
85
86         /// can we move into this cell (see macroarg.h)
87         bool isActive() const;
88         /// request "external features"
89         void validate(LaTeXFeatures & features) const;
90
91         /// replace in all cells
92         void replace(ReplaceData &);
93         /// do we contain a given pattern?
94         bool contains(MathData const &) const;
95         /// glue everything to a single cell
96         MathData glue() const;
97
98         /// debug helper
99         void dump() const;
100
101         /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
102         void write(WriteStream & os) const;
103         /// writes [, name(), and args in []
104         void normalize(NormalStream & os) const;
105         ///
106         int latex(Buffer const &, odocstream & os,
107                         OutputParams const & runparams) const;
108
109         /// This signal is emitted when the inset is destroyed.
110         boost::signal<void()> * destroyedSignal() { return &destroyed; }
111         
112         /// draw four angular markers
113         void drawMarkers(PainterInfo & pi, int x, int y) const;
114         /// draw two angular markers
115         void drawMarkers2(PainterInfo & pi, int x, int y) const;
116         ///
117         bool setMouseHover(bool mouse_hover);
118
119 protected:
120         ///
121         InsetMathNest(InsetMathNest const & inset);
122         ///
123         InsetMathNest & operator=(InsetMathNest const &);
124
125         ///
126         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
127         /// do we want to handle this event?
128         bool getStatus(Cursor & cur, FuncRequest const & cmd,
129                 FuncStatus & status) const;
130         ///
131         void handleFont(Cursor & cur,
132                 docstring const & arg, docstring const & font);
133         void handleFont(Cursor & cur,
134                 docstring const & arg, char const * const font);
135         ///
136         void handleFont2(Cursor & cur, docstring const & arg);
137
138         /// interpret \p c and insert the result at the current position of
139         /// of \p cur. Return whether the cursor should stay in the formula.
140         bool interpretChar(Cursor & cur, char_type c);
141         ///
142         bool script(Cursor & cur, bool,
143                 docstring const & save_selection = docstring());
144
145 public:
146         /// interpret \p str and insert the result at the current position of
147         /// \p cur if it is something known. Return whether \p cur was
148         /// inserted.
149         bool interpretString(Cursor & cur, docstring const & str);
150
151 private:
152         /// lfun handler
153         void lfunMousePress(Cursor &, FuncRequest &);
154         ///
155         void lfunMouseRelease(Cursor &, FuncRequest &);
156         ///
157         void lfunMouseMotion(Cursor &, FuncRequest &);
158
159 protected:
160         /// we store the cells in a vector
161         typedef std::vector<MathData> cells_type;
162         /// thusly:
163         cells_type cells_;
164         /// if the inset is locked, it can't be entered with the cursor
165         bool lock_;
166         ///
167         bool mouse_hover_;
168
169 private:
170         /// This signal is emitted when the inset is destroyed.
171         boost::signal<void()> destroyed;
172 };
173
174
175
176 } // namespace lyx
177 #endif