]> git.lyx.org Git - lyx.git/blob - src/insets/inset.h
cad92c891f3910f48b1d790dcd98e79e5aae1e3e
[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 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                 BOX_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 std::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(std::string const & s) { name_ = s; }
203         ///
204         std::string const & getInsetName() const { return name_; }
205         ///
206         void setOwner(UpdatableInset * inset) { owner_ = inset; }
207         ///
208         UpdatableInset * owner() const { return owner_; }
209         ///
210         void setBackgroundColor(LColor_color);
211         ///
212         LColor_color backgroundColor() const;
213         ///
214         int x() const { return top_x; }
215         ///
216         int y() const { return top_baseline; }
217         //
218         // because we could have fake text insets and have to call this
219         // inside them without cast!!!
220         ///
221         virtual LyXText * getLyXText(BufferView const *,
222                                      bool recursive = false) const;
223         ///
224         virtual void deleteLyXText(BufferView *, bool = true) const {}
225         /// returns the actuall scroll-value
226         virtual int scroll(bool recursive=true) const {
227                 if (!recursive || !owner_)
228                         return scx;
229                 return 0;
230         }
231
232         /// try to get a inset pointer from it's id if we have
233         /// an inset to give back!
234         virtual InsetOld * getInsetFromID(int /*id*/) const { return 0; }
235         /// if this insets owns paragraphs (f.ex. InsetText) then it
236         /// should return it's very first one!
237         virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
238         ///
239         virtual bool haveParagraphs() const {
240                 return false;
241         }
242
243         /// return the cursor if we own one otherwise giv'em just the
244         /// BufferView cursor to work with.
245         virtual LyXCursor const & cursor(BufferView * bview) const;
246         /// id functions
247         int id() const;
248         ///
249         void id(int id_arg);
250
251         /// used to toggle insets
252         // is the inset open?
253         virtual bool isOpen() const { return false; }
254         /// open the inset
255         virtual void open(BufferView *) {}
256         /// close the inset
257         virtual void close(BufferView *) const {}
258         /// check if the font of the char we want inserting is correct
259         /// and modify it if it is not.
260         virtual bool checkInsertChar(LyXFont &);
261         /// we need this here because collapsed insets are only EDITABLE
262         virtual void setFont(BufferView *, LyXFont const &,
263                          bool toggleall = false, bool selectall = false);
264         ///
265         // needed for spellchecking text
266         ///
267         virtual bool allowSpellcheck() const { return false; }
268
269         // should this inset be handled like a normal charater
270         virtual bool isChar() const { return false; }
271         // is this equivalent to a letter?
272         virtual bool isLetter() const { return false; }
273         // is this equivalent to a space (which is BTW different from
274         // a line separator)?
275         virtual bool isSpace() const { return false; }
276         // should we break lines after this inset?
277         virtual bool isLineSeparator() const { return false; }
278         // if this inset has paragraphs should they be output all as default
279         // paragraphs with "Standard" layout?
280         virtual bool forceDefaultParagraphs(InsetOld const *) const;
281         /** returns true if, when outputing LaTeX, font changes should
282             be closed before generating this inset. This is needed for
283             insets that may contain several paragraphs */
284         virtual bool noFontChange() const { return false; }
285         //
286         virtual void getDrawFont(LyXFont &) const {}
287         /* needed for widths which are % of something
288            returns the value of \textwidth in this inset. Most of the
289            time this is the width of the workarea, but if there is a
290            minipage somewhere, it will be the width of this minipage */
291         virtual int latexTextWidth(BufferView *) const;
292
293         /// mark the inset contents as erased (for change tracking)
294         virtual void markErased() {}
295
296         /** Adds a LaTeX snippet to the Preview Loader for transformation
297          *  into a bitmap image. Does not start the laoding process.
298          *
299          *  Most insets have no interest in this capability, so the method
300          *  defaults to empty.
301          */
302         virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
303 protected:
304         ///
305         mutable int top_x;
306         ///
307         mutable int top_baseline;
308         ///
309         mutable int scx;
310         /// Used to identify the inset for cursor positioning when undoing
311         unsigned int id_;
312         ///
313         static unsigned int inset_id;
314         ///
315         mutable Dimension dim_;
316
317 private:
318         ///
319         UpdatableInset * owner_;
320         ///
321         std::string name_;
322         /** We store the LColor::color value as an int to get LColor.h out
323          *  of the header file.
324          */
325         int background_color_;
326 };
327
328
329 /** \c InsetOld_code is a wrapper for InsetOld::Code.
330  *  It can be forward-declared and passed as a function argument without
331  *  having to expose inset.h.
332  */
333 class InsetOld_code {
334         InsetOld::Code val_;
335 public:
336         InsetOld_code(InsetOld::Code val) : val_(val) {}
337         operator InsetOld::Code() const{ return val_; }
338 };
339
340
341 /**
342  * returns true if pointer argument is valid
343  * and points to an editable inset
344  */
345 bool isEditableInset(InsetOld const * i);
346
347
348 /**
349  * returns true if pointer argument is valid
350  * and points to a highly editable inset
351  */
352 bool isHighlyEditableInset(InsetOld const * i);
353
354 #endif