]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.h
4db158a2bac34fa5b6a69d628bfbd279fc9322a3
[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 class MathArray;
18
19
20 /** Abstract base class for all math objects that contain nested items.
21     This is basically everything that is not a single character or a
22     single symbol.
23 */
24
25 class MathNestInset : public MathDimInset {
26 public:
27         /// nestinsets have a fixed size to start with
28         explicit MathNestInset(idx_type ncells);
29
30         /// the size is usuall some sort of convex hull of the cells
31         /// hides inset::metrics() intentionally!
32         void metrics(MetricsInfo const & mi) const;
33         /// draw background if locked
34         void draw(PainterInfo & pi, int x, int y) const;
35         /// draw selection background
36         void drawSelection(PainterInfo & pi,
37                 idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
38         /// appends itself with macro arguments substituted
39         void substitute(MathMacro const & macro);
40         /// identifies NestInsets
41         MathNestInset * asNestInset() { return this; }
42         /// identifies NestInsets
43         MathNestInset const * asNestInset() const { return this; }
44         /// get cursor position
45         void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
46
47         /// order of movement through the cells when pressing the left key
48         bool idxLeft(idx_type & idx, pos_type & pos) const;
49         /// order of movement through the cells when pressing the right key
50         bool idxRight(idx_type & idx, pos_type & pos) const;
51
52         /// move one physical cell up
53         bool idxNext(idx_type & idx, pos_type & pos) const;
54         /// move one physical cell down
55         bool idxPrev(idx_type & idx, pos_type & pos) const;
56
57         /// target pos when we enter the inset from the left by pressing "Right"
58         bool idxFirst(idx_type & idx, pos_type & pos) const;
59         /// target pos when we enter the inset from the right by pressing "Left"
60         bool idxLast(idx_type & idx, pos_type & pos) const;
61
62         /// where should we go if we press home?
63         bool idxHome(idx_type & idx, pos_type & pos) const;
64         /// where should we go if we press end?
65         bool idxEnd(idx_type & idx, pos_type & pos) 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         /// match in all cells
87         bool match(MathAtom const &) const;
88         /// replace in all cells
89         void replace(ReplaceData &);
90         /// do we contain a given pattern?
91         bool contains(MathArray const &) const;
92         /// glue everything to a single cell
93         MathArray glue() const;
94
95         /// debug helper
96         void dump() const;
97         /// is the cursor currently somewhere within this inset?
98         virtual bool editing() const;
99
100         /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
101         void write(WriteStream & os) const;
102         /// writes [, name(), and args in []
103         void normalize(NormalStream & os) const;
104
105         /// local dispatcher
106         dispatch_result priv_dispatch(FuncRequest const & cmd,
107                 idx_type & idx, pos_type & pos);
108
109 protected:
110         /// we store the cells in a vector
111         typedef std::vector<MathArray> cells_type;
112         /// thusly:
113         cells_type cells_;
114         /// if the inset is locked, it can't be entered with the cursor
115         bool lock_;
116
117         /// draw four angular markers
118         void drawMarkers(PainterInfo & pi, int x, int y) const;
119         /// draw two angular markers
120         void drawMarkers2(PainterInfo & pi, int x, int y) const;
121
122         /// add space for markers
123         void metricsMarkers(int frame = 1) const;
124         /// add space for markers
125         void metricsMarkers2(int frame = 1) const;
126
127 };
128
129 #endif