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