]> git.lyx.org Git - lyx.git/blob - src/insets/insetbase.h
Part of IU.
[lyx.git] / src / insets / insetbase.h
1 // -*- C++ -*-
2 /**
3  * \file insetbase.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author none
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSETBASE_H
13 #define INSETBASE_H
14
15 #include <string>
16 #include <vector>
17 #include <memory>
18
19 class Buffer;
20 class BufferView;
21 class DispatchResult;
22 class FuncRequest;
23 class LaTeXFeatures;
24 class LCursor;
25 class MathInset;
26 class MetricsInfo;
27 class Dimension;
28 class PainterInfo;
29 class UpdatableInset;
30
31 /// Common base class to all insets
32 class InsetBase {
33 public:
34         ///
35         typedef ptrdiff_t  difference_type;
36         /// short of anything else reasonable
37         typedef size_t     size_type;
38         /// type for cell indices
39         typedef size_t     idx_type;
40         /// type for cursor positions
41         typedef ptrdiff_t  pos_type;
42         /// type for row numbers
43         typedef size_t     row_type;
44         /// type for column numbers
45         typedef size_t     col_type;
46
47         /// virtual base class destructor
48         virtual ~InsetBase() {}
49         /// replicate ourselves
50         virtual std::auto_ptr<InsetBase> clone() const = 0;
51
52         /// identification as math inset
53         virtual MathInset * asMathInset() { return 0; }
54         /// identification as non-math inset
55         virtual UpdatableInset * asUpdatableInset() { return 0; }
56
57         // the real dispatcher
58         DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
59
60         /// cursor enters
61         virtual void edit(LCursor & cur, bool left);
62         /// cursor enters
63         virtual void edit(LCursor & cur, int x, int y);
64
65         /// compute the size of the object returned in dim
66         virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
67         /// draw inset and update (xo, yo)-cache
68         virtual void draw(PainterInfo & pi, int x, int y) const = 0;
69         /// last drawn position for 'important' insets
70         virtual int x() const { return 0; }
71         /// last drawn position for 'important' insets
72         virtual int y() const { return 0; }
73  
74         /// number of embedded cells
75         virtual size_t nargs() const { return 0; }
76         /// number of rows in gridlike structures
77         virtual size_t nrows() const { return 0; }
78         /// number of columns in gridlike structures
79         virtual size_t ncols() const { return 0; }
80
81         /// request "external features"
82         virtual void validate(LaTeXFeatures &) const {}
83         /// Appends \c list with all labels found within this inset.
84         virtual void getLabelList(Buffer const &,
85                                   std::vector<std::string> & /* list */) const {}
86         /// describe content if cursor inside
87         virtual void infoize(std::ostream &) const {}
88         /// describe content if cursor behind
89         virtual void infoize2(std::ostream &) const {}
90 protected:
91         // the real dispatcher
92         virtual
93         DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
94 public:
95         /** This is not quite the correct place for this enum. I think
96             the correct would be to let each subclass of Inset declare
97             its own enum code. Actually the notion of an InsetOld::Code
98             should be avoided, but I am not sure how this could be done
99             in a cleaner way. */
100         enum Code {
101                 ///
102                 NO_CODE, // 0
103                 ///
104                 TOC_CODE,  // do these insets really need a code? (ale)
105                 ///
106                 QUOTE_CODE,
107                 ///
108                 MARK_CODE,
109                 ///
110                 REF_CODE,
111                 ///
112                 URL_CODE, // 5
113                 ///
114                 HTMLURL_CODE,
115                 ///
116                 SEPARATOR_CODE,
117                 ///
118                 ENDING_CODE,
119                 ///
120                 LABEL_CODE,
121                 ///
122                 NOTE_CODE, // 10
123                 ///
124                 ACCENT_CODE,
125                 ///
126                 MATH_CODE,
127                 ///
128                 INDEX_CODE,
129                 ///
130                 INCLUDE_CODE,
131                 ///
132                 GRAPHICS_CODE, // 15
133                 ///
134                 BIBITEM_CODE,
135                 ///
136                 BIBTEX_CODE,
137                 ///
138                 TEXT_CODE,
139                 ///
140                 ERT_CODE,
141                 ///
142                 FOOT_CODE, // 20
143                 ///
144                 MARGIN_CODE,
145                 ///
146                 FLOAT_CODE,
147                 ///
148                 WRAP_CODE,
149                 ///
150                 SPACE_CODE, // 25
151                 ///
152                 SPECIALCHAR_CODE,
153                 ///
154                 TABULAR_CODE,
155                 ///
156                 EXTERNAL_CODE,
157 #if 0
158                 ///
159                 THEOREM_CODE,
160 #endif
161                 ///
162                 CAPTION_CODE,
163                 ///
164                 MATHMACRO_CODE, // 30
165                 ///
166                 ERROR_CODE,
167                 ///
168                 CITE_CODE,
169                 ///
170                 FLOAT_LIST_CODE,
171                 ///
172                 INDEX_PRINT_CODE,
173                 ///
174                 OPTARG_CODE, // 35
175                 ///
176                 ENVIRONMENT_CODE,
177                 ///
178                 HFILL_CODE,
179                 ///
180                 NEWLINE_CODE,
181                 ///
182                 LINE_CODE,
183                 ///
184                 BRANCH_CODE, // 40
185                 ///
186                 BOX_CODE,
187                 ///
188                 CHARSTYLE_CODE,
189                 ///
190                 VSPACE_CODE,
191                 ///
192                 MATHGRID_CODE,
193                 ///
194                 MATHHULL_CODE
195         };
196         /// returns LyX code associated with the inset. Used for TOC, ...)
197         virtual InsetBase::Code lyxCode() const { return NO_CODE; }
198
199 };
200
201 #endif