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