]> git.lyx.org Git - lyx.git/blob - src/insets/inset.h
Remove #include "LColor.h" from inset.h.
[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 class Buffer;
23 class EnumLColor;
24 class FuncRequest;
25 class LatexRunParams;
26 class LyXCursor;
27 class LyXFont;
28 class LyXLex;
29 class LyXText;
30 class Painter;
31 class Paragraph;
32 class UpdatableInset;
33 class WordLangTuple;
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                 BRANCH_CODE
134         };
135
136         ///
137         enum {
138                 ///
139                 TEXT_TO_INSET_OFFSET = 2
140         };
141
142         ///
143         enum EDITABLE {
144                 ///
145                 NOT_EDITABLE = 0,
146                 ///
147                 IS_EDITABLE,
148                 ///
149                 HIGHLY_EDITABLE
150         };
151
152         ///
153         typedef dispatch_result RESULT;
154
155         ///
156         InsetOld();
157         ///
158         InsetOld(InsetOld const & in);
159         ///
160         int ascent() const;
161         ///
162         int descent() const;
163         ///
164         int width() const;
165         /// what appears in the minibuffer when opening
166         virtual string const editMessage() const;
167         ///
168         virtual EDITABLE editable() const;
169         ///
170         virtual bool isTextInset() const { return false; }
171         /// return true if the inset should be removed automatically
172         virtual bool autoDelete() const;
173         /// returns true the inset can hold an inset of given type
174         virtual bool insetAllowed(InsetOld::Code) const { return false; }
175         /// wrapper around the above
176         bool insetAllowed(InsetOld * in) const;
177         ///
178         virtual void write(Buffer const &, std::ostream &) const = 0;
179         ///
180         virtual void read(Buffer const &, LyXLex & lex) = 0;
181         /// returns the number of rows (\n's) of generated tex code.
182         virtual int latex(Buffer const &, std::ostream &,
183                           LatexRunParams const &) const = 0;
184         ///
185         virtual int ascii(Buffer const &,
186                           std::ostream &, int linelen = 0) const = 0;
187         ///
188         virtual int linuxdoc(Buffer const &, std::ostream &) const = 0;
189         ///
190         virtual int docbook(Buffer const &, std::ostream &, bool) const = 0;
191
192         /// returns LyX code associated with the inset. Used for TOC, ...)
193         virtual InsetOld::Code lyxCode() const { return NO_CODE; }
194
195         /// returns true to override begin and end inset in file
196         virtual bool directWrite() const;
197
198         ///
199         void setInsetName(string const & s) { name_ = s; }
200         ///
201         string const & getInsetName() const { return name_; }
202         ///
203         void setOwner(UpdatableInset * inset) { owner_ = inset; }
204         ///
205         UpdatableInset * owner() const { return owner_; }
206         ///
207         void setBackgroundColor(EnumLColor);
208         ///
209         EnumLColor backgroundColor() const;
210         ///
211         int x() const { return top_x; }
212         ///
213         int y() const { return top_baseline; }
214         //
215         // because we could have fake text insets and have to call this
216         // inside them without cast!!!
217         ///
218         virtual LyXText * getLyXText(BufferView const *,
219                                      bool recursive = false) const;
220         ///
221         virtual void deleteLyXText(BufferView *, bool = true) const {}
222         /// returns the actuall scroll-value
223         virtual int scroll(bool recursive=true) const {
224                 if (!recursive || !owner_)
225                         return scx;
226                 return 0;
227         }
228
229         /// try to get a inset pointer from it's id if we have
230         /// an inset to give back!
231         virtual InsetOld * getInsetFromID(int /*id*/) const { return 0; }
232         /// if this insets owns paragraphs (f.ex. InsetText) then it
233         /// should return it's very first one!
234         virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
235         ///
236         virtual bool haveParagraphs() const {
237                 return false;
238         }
239
240         /// return the cursor if we own one otherwise giv'em just the
241         /// BufferView cursor to work with.
242         virtual LyXCursor const & cursor(BufferView * bview) const;
243         /// id functions
244         int id() const;
245         ///
246         void id(int id_arg);
247
248         /// used to toggle insets
249         // is the inset open?
250         virtual bool isOpen() const { return false; }
251         /// open the inset
252         virtual void open(BufferView *) {}
253         /// close the inset
254         virtual void close(BufferView *) const {}
255         /// check if the font of the char we want inserting is correct
256         /// and modify it if it is not.
257         virtual bool checkInsertChar(LyXFont &);
258         /// we need this here because collapsed insets are only EDITABLE
259         virtual void setFont(BufferView *, LyXFont const &,
260                          bool toggleall = false, bool selectall = false);
261         ///
262         // needed for spellchecking text
263         ///
264         virtual bool allowSpellcheck() const { return false; }
265
266         // should this inset be handled like a normal charater
267         virtual bool isChar() const { return false; }
268         // is this equivalent to a letter?
269         virtual bool isLetter() const { return false; }
270         // is this equivalent to a space (which is BTW different from
271         // a line separator)?
272         virtual bool isSpace() const { return false; }
273         // should we break lines after this inset?
274         virtual bool isLineSeparator() const { return false; }
275         // if this inset has paragraphs should they be output all as default
276         // paragraphs with "Standard" layout?
277         virtual bool forceDefaultParagraphs(InsetOld const *) const;
278         /** returns true if, when outputing LaTeX, font changes should
279             be closed before generating this inset. This is needed for
280             insets that may contain several paragraphs */
281         virtual bool noFontChange() const { return false; }
282         //
283         virtual void getDrawFont(LyXFont &) const {}
284         /* needed for widths which are % of something
285            returns the value of \textwidth in this inset. Most of the
286            time this is the width of the workarea, but if there is a
287            minipage somewhere, it will be the width of this minipage */
288         virtual int latexTextWidth(BufferView *) const;
289
290         /// mark the inset contents as erased (for change tracking)
291         virtual void markErased() {}
292
293         /** Adds a LaTeX snippet to the Preview Loader for transformation
294          *  into a bitmap image. Does not start the laoding process.
295          *
296          *  Most insets have no interest in this capability, so the method
297          *  defaults to empty.
298          */
299         virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
300
301         /** Find the PreviewLoader, add a LaTeX snippet to it and
302          *  start the loading process.
303          *
304          *  Most insets have no interest in this capability, so the method
305          *  defaults to empty.
306          */
307         virtual void generatePreview() const {}
308
309 protected:
310         ///
311         mutable int top_x;
312         ///
313         mutable int top_baseline;
314         ///
315         mutable int scx;
316         /// Used to identify the inset for cursor positioning when undoing
317         unsigned int id_;
318         ///
319         static unsigned int inset_id;
320         ///
321         mutable Dimension dim_;
322
323 private:
324         ///
325         UpdatableInset * owner_;
326         ///
327         string name_;
328         /** We store the LColor::color value as an int to get LColor.h out
329          *  of the header file.
330          */
331         int background_color_;
332 };
333
334
335 /**
336  * returns true if pointer argument is valid
337  * and points to an editable inset
338  */
339 bool isEditableInset(InsetOld const * i);
340
341
342 /**
343  * returns true if pointer argument is valid
344  * and points to a highly editable inset
345  */
346 bool isHighlyEditableInset(InsetOld const * i);
347
348 #endif