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