]> git.lyx.org Git - lyx.git/blob - src/insets/inset.h
9d0313462ab00d836421c5ab78bec98dff5440e4
[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 "LColor.h"
19 #include "insetbase.h"
20 #include "dimension.h"
21 #include "support/types.h"
22
23 #include <vector>
24
25 class LyXFont;
26 class Buffer;
27 class Painter;
28 class LatexRunParams;
29 class LyXText;
30 class LyXLex;
31 class Paragraph;
32 class LyXCursor;
33 class FuncRequest;
34 class WordLangTuple;
35 class ParagraphList;
36 class UpdatableInset;
37
38 namespace lyx {
39 namespace graphics {
40         class PreviewLoader;
41 }
42 }
43
44 /// Insets
45 class InsetOld : public InsetBase {
46 public:
47         /** This is not quite the correct place for this enum. I think
48             the correct would be to let each subclass of Inset declare
49             its own enum code. Actually the notion of an InsetOld::Code
50             should be avoided, but I am not sure how this could be done
51             in a cleaner way. */
52         enum Code {
53                 ///
54                 NO_CODE, // 0
55                 ///
56                 TOC_CODE,  // do these insets really need a code? (ale)
57                 ///
58                 QUOTE_CODE,
59                 ///
60                 MARK_CODE,
61                 ///
62                 REF_CODE,
63                 ///
64                 URL_CODE, // 5
65                 ///
66                 HTMLURL_CODE,
67                 ///
68                 SEPARATOR_CODE,
69                 ///
70                 ENDING_CODE,
71                 ///
72                 LABEL_CODE,
73                 ///
74                 NOTE_CODE, // 10
75                 ///
76                 ACCENT_CODE,
77                 ///
78                 MATH_CODE,
79                 ///
80                 INDEX_CODE,
81                 ///
82                 INCLUDE_CODE,
83                 ///
84                 GRAPHICS_CODE, // 15
85                 ///
86                 BIBITEM_CODE,
87                 ///
88                 BIBTEX_CODE,
89                 ///
90                 TEXT_CODE,
91                 ///
92                 ERT_CODE,
93                 ///
94                 FOOT_CODE, // 20
95                 ///
96                 MARGIN_CODE,
97                 ///
98                 FLOAT_CODE,
99                 ///
100                 WRAP_CODE,
101                 ///
102                 MINIPAGE_CODE,
103                 ///
104                 SPACE_CODE, // 25
105                 ///
106                 SPECIALCHAR_CODE,
107                 ///
108                 TABULAR_CODE,
109                 ///
110                 EXTERNAL_CODE,
111 #if 0
112                 ///
113                 THEOREM_CODE,
114 #endif
115                 ///
116                 CAPTION_CODE,
117                 ///
118                 MATHMACRO_CODE, // 30
119                 ///
120                 ERROR_CODE,
121                 ///
122                 CITE_CODE,
123                 ///
124                 FLOAT_LIST_CODE,
125                 ///
126                 INDEX_PRINT_CODE,
127                 ///
128                 OPTARG_CODE, // 35
129                 ///
130                 ENVIRONMENT_CODE,
131                 ///
132                 HFILL_CODE,
133                 ///
134                 NEWLINE_CODE,
135                 ///
136                 BRANCH_CODE
137         };
138
139         ///
140         enum {
141                 ///
142                 TEXT_TO_INSET_OFFSET = 2
143         };
144
145         ///
146         enum EDITABLE {
147                 ///
148                 NOT_EDITABLE = 0,
149                 ///
150                 IS_EDITABLE,
151                 ///
152                 HIGHLY_EDITABLE
153         };
154
155         ///
156         typedef dispatch_result RESULT;
157
158         ///
159         InsetOld();
160         ///
161         InsetOld(InsetOld const & in);
162         ///
163         int ascent() const;
164         ///
165         int descent() const;
166         ///
167         int width() const;
168         /// what appears in the minibuffer when opening
169         virtual string const editMessage() const;
170         ///
171         virtual EDITABLE editable() const;
172         ///
173         virtual bool isTextInset() const { return false; }
174         /// return true if the inset should be removed automatically
175         virtual bool autoDelete() const;
176         /// returns true the inset can hold an inset of given type
177         virtual bool insetAllowed(InsetOld::Code) const { return false; }
178         /// wrapper around the above
179         bool insetAllowed(InsetOld * in) const;
180         ///
181         virtual void write(Buffer const *, std::ostream &) const = 0;
182         ///
183         virtual void read(Buffer const *, LyXLex & lex) = 0;
184         /// returns the number of rows (\n's) of generated tex code.
185         virtual int latex(Buffer const *, std::ostream &,
186                           LatexRunParams const &) const = 0;
187         ///
188         virtual int ascii(Buffer const *,
189                           std::ostream &, int linelen = 0) const = 0;
190         ///
191         virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
192         ///
193         virtual int docbook(Buffer const *, std::ostream &, bool) const = 0;
194
195         /// returns LyX code associated with the inset. Used for TOC, ...)
196         virtual InsetOld::Code lyxCode() const { return NO_CODE; }
197
198         /// returns true to override begin and end inset in file
199         virtual bool directWrite() const;
200
201         ///
202         void setInsetName(string const & s) { name_ = s; }
203         ///
204         string const & getInsetName() const { return name_; }
205         ///
206         void setOwner(UpdatableInset * inset) { owner_ = inset; }
207         ///
208         UpdatableInset * owner() const { return owner_; }
209         ///
210         void parOwner(Paragraph * par) { par_owner_ = par; }
211         ///
212         Paragraph * parOwner() const { return par_owner_; }
213         ///
214         void setBackgroundColor(LColor::color);
215         ///
216         LColor::color backgroundColor() const;
217         ///
218         int x() const { return top_x; }
219         ///
220         int y() const { return top_baseline; }
221         //
222         // because we could have fake text insets and have to call this
223         // inside them without cast!!!
224         ///
225         virtual LyXText * getLyXText(BufferView const *,
226                                      bool recursive = false) const;
227         ///
228         virtual void deleteLyXText(BufferView *, bool = true) const {}
229         /// returns the actuall scroll-value
230         virtual int scroll(bool recursive=true) const {
231                 if (!recursive || !owner_)
232                         return scx;
233                 return 0;
234         }
235
236         /// try to get a inset pointer from it's id if we have
237         /// an inset to give back!
238         virtual InsetOld * getInsetFromID(int /*id*/) const { return 0; }
239         /// if this insets owns paragraphs (f.ex. InsetText) then it
240         /// should return it's very first one!
241         virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
242         ///
243         virtual bool haveParagraphs() const {
244                 return false;
245         }
246
247         /// return the cursor if we own one otherwise giv'em just the
248         /// BufferView cursor to work with.
249         virtual LyXCursor const & cursor(BufferView * bview) const;
250         /// id functions
251         int id() const;
252         ///
253         void id(int id_arg);
254
255         /// used to toggle insets
256         // is the inset open?
257         virtual bool isOpen() const { return false; }
258         /// open the inset
259         virtual void open(BufferView *) {}
260         /// close the inset
261         virtual void close(BufferView *) const {}
262         /// check if the font of the char we want inserting is correct
263         /// and modify it if it is not.
264         virtual bool checkInsertChar(LyXFont &);
265         /// we need this here because collapsed insets are only EDITABLE
266         virtual void setFont(BufferView *, LyXFont const &,
267                          bool toggleall = false, bool selectall = false);
268         ///
269         // needed for spellchecking text
270         ///
271         virtual bool allowSpellcheck() const { return false; }
272
273         // should this inset be handled like a normal charater
274         virtual bool isChar() const { return false; }
275         // is this equivalent to a letter?
276         virtual bool isLetter() const { return false; }
277         // is this equivalent to a space (which is BTW different from
278         // a line separator)?
279         virtual bool isSpace() const { return false; }
280         // should we break lines after this inset?
281         virtual bool isLineSeparator() const { return false; }
282         // if this inset has paragraphs should they be output all as default
283         // paragraphs with "Standard" layout?
284         virtual bool forceDefaultParagraphs(InsetOld const *) const;
285         /** returns true if, when outputing LaTeX, font changes should
286             be closed before generating this inset. This is needed for
287             insets that may contain several paragraphs */
288         virtual bool noFontChange() const { return false; }
289         //
290         virtual void getDrawFont(LyXFont &) const {}
291         /* needed for widths which are % of something
292            returns the value of \textwidth in this inset. Most of the
293            time this is the width of the workarea, but if there is a
294            minipage somewhere, it will be the width of this minipage */
295         virtual int latexTextWidth(BufferView *) const;
296
297         /// mark the inset contents as erased (for change tracking)
298         virtual void markErased() {}
299
300         /** Adds a LaTeX snippet to the Preview Loader for transformation
301          *  into a bitmap image. Does not start the laoding process.
302          *
303          *  Most insets have no interest in this capability, so the method
304          *  defaults to empty.
305          */
306         virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
307
308         /** Find the PreviewLoader, add a LaTeX snippet to it and
309          *  start the loading process.
310          *
311          *  Most insets have no interest in this capability, so the method
312          *  defaults to empty.
313          */
314         virtual void generatePreview() const {}
315
316 protected:
317         ///
318         mutable int top_x;
319         ///
320         mutable int top_baseline;
321         ///
322         mutable int scx;
323         /// Used to identify the inset for cursor positioning when undoing
324         unsigned int id_;
325         ///
326         static unsigned int inset_id;
327         ///
328         mutable Dimension dim_;
329
330 private:
331         ///
332         UpdatableInset * owner_;
333         /// the paragraph in which this inset has been inserted
334         Paragraph * par_owner_;
335         ///
336         string name_;
337         ///
338         LColor::color background_color_;
339 };
340
341
342 /**
343  * returns true if pointer argument is valid
344  * and points to an editable inset
345  */
346 bool isEditableInset(InsetOld const * i);
347
348
349 /**
350  * returns true if pointer argument is valid
351  * and points to a highly editable inset
352  */
353 bool isHighlyEditableInset(InsetOld const * i);
354
355 #endif