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