]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.h
853a33aa54f7a8ca89f0b4cf0943d50987a45038
[lyx.git] / src / mathed / math_nestinset.h
1 // -*- C++ -*-
2 /**
3  * \file math_nestinset.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 "math_diminset.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 MathNestInset : public MathDimInset {
24 public:
25         /// nestinsets have a fixed size to start with
26         explicit MathNestInset(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,
35                 idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
36         /// appends itself with macro arguments substituted
37         void substitute(MathMacro const & macro);
38         /// identifies NestInsets
39         MathNestInset * asNestInset() { return this; }
40         /// identifies NestInsets
41         MathNestInset const * asNestInset() const { return this; }
42         /// get cursor position
43         void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
44         ///
45         void edit(LCursor & cur, int, int);
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         /// where should we go if we press home?
63         bool idxHome(LCursor &) const;
64         /// where should we go if we press end?
65         bool idxEnd(LCursor &) const;
66
67         /// number of cells currently governed by us
68         idx_type nargs() const;
69         /// access to the lock
70         bool lock() const;
71         /// access to the lock
72         void lock(bool);
73         /// get notification when the cursor leaves this inset
74         void notifyCursorLeaves(idx_type);
75
76         /// direct access to the cell
77         MathArray & cell(idx_type);
78         /// direct access to the cell
79         MathArray const & cell(idx_type) const;
80
81         /// can we move into this cell (see macroarg.h)
82         bool isActive() const;
83         /// request "external features"
84         void validate(LaTeXFeatures & features) const;
85
86         /// replace in all cells
87         void replace(ReplaceData &);
88         /// do we contain a given pattern?
89         bool contains(MathArray const &) const;
90         /// glue everything to a single cell
91         MathArray glue() const;
92
93         /// debug helper
94         void dump() const;
95
96         /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
97         void write(WriteStream & os) const;
98         /// writes [, name(), and args in []
99         void normalize(NormalStream & os) const;
100 protected:
101         ///
102         DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
103         ///
104         void handleFont(LCursor & cur,
105                 std::string const & arg, std::string const & font);
106         ///
107         void handleFont2(LCursor & cur, std::string const & arg);
108
109         /// we store the cells in a vector
110         typedef std::vector<MathArray> cells_type;
111         /// thusly:
112         cells_type cells_;
113         /// if the inset is locked, it can't be entered with the cursor
114         bool lock_;
115 };
116
117 #endif