]> git.lyx.org Git - features.git/blob - src/insets/inset.h
f1242d6c7f28419e9c09d545cc491456d55cd591
[features.git] / src / insets / inset.h
1 // -*- C++ -*-
2 /**
3  * \file inset.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author Jürgen Vigna
9  * \author Lars Gullik Bjønnes
10  * \author Matthias Ettrich
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef INSETOLD_H
16 #define INSETOLD_H
17
18 #include "insetbase.h"
19 #include "dimension.h"
20 #include "ParagraphList_fwd.h"
21
22
23 class Buffer;
24 class LColor_color;
25 class FuncRequest;
26 class OutputParams;
27 class CursorSlice;
28 class LyXLex;
29 class LyXText;
30 class Painter;
31 class Paragraph;
32 class UpdatableInset;
33
34 namespace lyx {
35 namespace graphics {
36         class PreviewLoader;
37 }
38 }
39
40 /// Insets
41 class InsetOld : public InsetBase {
42 public:
43         /** This is not quite the correct place for this enum. I think
44             the correct would be to let each subclass of Inset declare
45             its own enum code. Actually the notion of an InsetOld::Code
46             should be avoided, but I am not sure how this could be done
47             in a cleaner way. */
48         enum Code {
49                 ///
50                 NO_CODE, // 0
51                 ///
52                 TOC_CODE,  // do these insets really need a code? (ale)
53                 ///
54                 QUOTE_CODE,
55                 ///
56                 MARK_CODE,
57                 ///
58                 REF_CODE,
59                 ///
60                 URL_CODE, // 5
61                 ///
62                 HTMLURL_CODE,
63                 ///
64                 SEPARATOR_CODE,
65                 ///
66                 ENDING_CODE,
67                 ///
68                 LABEL_CODE,
69                 ///
70                 NOTE_CODE, // 10
71                 ///
72                 ACCENT_CODE,
73                 ///
74                 MATH_CODE,
75                 ///
76                 INDEX_CODE,
77                 ///
78                 INCLUDE_CODE,
79                 ///
80                 GRAPHICS_CODE, // 15
81                 ///
82                 BIBITEM_CODE,
83                 ///
84                 BIBTEX_CODE,
85                 ///
86                 TEXT_CODE,
87                 ///
88                 ERT_CODE,
89                 ///
90                 FOOT_CODE, // 20
91                 ///
92                 MARGIN_CODE,
93                 ///
94                 FLOAT_CODE,
95                 ///
96                 WRAP_CODE,
97                 ///
98                 SPACE_CODE, // 25
99                 ///
100                 SPECIALCHAR_CODE,
101                 ///
102                 TABULAR_CODE,
103                 ///
104                 EXTERNAL_CODE,
105 #if 0
106                 ///
107                 THEOREM_CODE,
108 #endif
109                 ///
110                 CAPTION_CODE,
111                 ///
112                 MATHMACRO_CODE, // 30
113                 ///
114                 ERROR_CODE,
115                 ///
116                 CITE_CODE,
117                 ///
118                 FLOAT_LIST_CODE,
119                 ///
120                 INDEX_PRINT_CODE,
121                 ///
122                 OPTARG_CODE, // 35
123                 ///
124                 ENVIRONMENT_CODE,
125                 ///
126                 HFILL_CODE,
127                 ///
128                 NEWLINE_CODE,
129                 ///
130                 LINE_CODE,
131                 ///
132                 BRANCH_CODE, // 40
133                 ///
134                 BOX_CODE,
135                 ///
136                 CHARSTYLE_CODE,
137                 ///
138                 VSPACE_CODE
139         };
140
141         ///
142         enum {
143                 ///
144                 TEXT_TO_INSET_OFFSET = 2
145         };
146
147         ///
148         enum EDITABLE {
149                 ///
150                 NOT_EDITABLE = 0,
151                 ///
152                 IS_EDITABLE,
153                 ///
154                 HIGHLY_EDITABLE
155         };
156
157         ///
158         InsetOld();
159         ///
160         InsetOld(InsetOld const & in);
161         ///
162         int ascent() const;
163         ///
164         int descent() const;
165         ///
166         int width() const;
167         /// what appears in the minibuffer when opening
168         virtual std::string const editMessage() const;
169         ///
170         virtual EDITABLE editable() const;
171         /// can we go further down on mouse click?
172         virtual bool descendable() const { return false; }
173         ///
174         virtual bool isTextInset() const { return false; }
175         /// return true if the inset should be removed automatically
176         virtual bool autoDelete() const;
177         /// returns true the inset can hold an inset of given type
178         virtual bool insetAllowed(InsetOld::Code) const { return false; }
179         /// wrapper around the above
180         bool insetAllowed(InsetOld * in) const;
181         ///
182         virtual void write(Buffer const &, std::ostream &) const = 0;
183         ///
184         virtual void read(Buffer const &, LyXLex & lex) = 0;
185         /// returns the number of rows (\n's) of generated tex code.
186         virtual int latex(Buffer const &, std::ostream &,
187                           OutputParams const &) const = 0;
188         ///
189         virtual int plaintext(Buffer const &, std::ostream &,
190                           OutputParams const &) const = 0;
191         ///
192         virtual int linuxdoc(Buffer const &, std::ostream &,
193                              OutputParams const &) const = 0;
194         ///
195         virtual int docbook(Buffer const &, std::ostream &,
196                             OutputParams const &) const = 0;
197
198         /// returns LyX code associated with the inset. Used for TOC, ...)
199         virtual InsetOld::Code lyxCode() const { return NO_CODE; }
200
201         /// returns true to override begin and end inset in file
202         virtual bool directWrite() const;
203
204         ///
205         void setInsetName(std::string const & s) { name_ = s; }
206         ///
207         std::string const & getInsetName() const { return name_; }
208         ///
209         void setOwner(UpdatableInset * inset) { owner_ = inset; }
210         ///
211         UpdatableInset * owner() const { return owner_; }
212         ///
213         virtual void setBackgroundColor(LColor_color);
214         ///
215         LColor_color backgroundColor() const;
216         ///
217         int x() const { return xo_; }
218         ///
219         int y() const { return yo_; }
220         /// returns the actual scroll-value
221         virtual int scroll(bool recursive = true) const;
222
223         /// if this insets owns text cells (e.g. InsetText) return cell num
224         virtual LyXText * getText(int /*num*/) const { return 0; }
225         ///
226         virtual int numParagraphs() const { return 0; }
227         /// returns cell covering position (x,y), -1 if none exists
228         virtual int getCell(int x, int y) const;
229
230         /// used to toggle insets
231         // is the inset open?
232         virtual bool isOpen() const { return false; }
233         /// open the inset
234         virtual void open() {}
235         /// close the inset
236         virtual void close() {}
237         // should this inset be handled like a normal charater
238         virtual bool isChar() const { return false; }
239         // is this equivalent to a letter?
240         virtual bool isLetter() const { return false; }
241         // is this equivalent to a space (which is BTW different from
242         // a line separator)?
243         virtual bool isSpace() const { return false; }
244         // should we have a non-filled line before this inset?
245         virtual bool display() const { return false; }
246         // should we break lines after this inset?
247         virtual bool isLineSeparator() const { return false; }
248         // if this inset has paragraphs should they be output all as default
249         // paragraphs with "Standard" layout?
250         virtual bool forceDefaultParagraphs(InsetOld const *) const;
251         /** returns true if, when outputing LaTeX, font changes should
252             be closed before generating this inset. This is needed for
253             insets that may contain several paragraphs */
254         virtual bool noFontChange() const { return false; }
255
256         /// mark the inset contents as erased (for change tracking)
257         virtual void markErased() {}
258
259         /// does this inset allows spellchecking?
260         virtual bool allowSpellCheck() const { return true; }
261
262         /** Adds a LaTeX snippet to the Preview Loader for transformation
263          *  into a bitmap image. Does not start the laoding process.
264          *
265          *  Most insets have no interest in this capability, so the method
266          *  defaults to empty.
267          */
268         virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
269 protected:
270         ///
271         mutable int xo_;
272         ///
273         mutable int yo_;
274         ///
275         mutable int scx;
276         ///
277         mutable Dimension dim_;
278
279 private:
280         ///
281         UpdatableInset * owner_;
282         ///
283         std::string name_;
284         /** We store the LColor::color value as an int to get LColor.h out
285          *  of the header file.
286          */
287         int background_color_;
288 };
289
290
291 /** \c InsetOld_code is a wrapper for InsetOld::Code.
292  *  It can be forward-declared and passed as a function argument without
293  *  having to expose inset.h.
294  */
295 class InsetOld_code {
296         InsetOld::Code val_;
297 public:
298         InsetOld_code(InsetOld::Code val) : val_(val) {}
299         operator InsetOld::Code() const { return val_; }
300 };
301
302
303 /**
304  * returns true if pointer argument is valid
305  * and points to an editable inset
306  */
307 bool isEditableInset(InsetOld const * inset);
308
309
310 /**
311  * returns true if pointer argument is valid
312  * and points to a highly editable inset
313  */
314 bool isHighlyEditableInset(InsetOld const * inset);
315
316 #endif