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