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