]> git.lyx.org Git - lyx.git/blob - src/insets/inset.h
79dfac6f82eb8a934388ac63a04890df6316d9fb
[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 OutputParams;
27 class LyXCursor;
28 class LyXFont;
29 class LyXLex;
30 class LyXText;
31 class Painter;
32 class Paragraph;
33 class UpdatableInset;
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                 LINE_CODE,
134                 ///
135                 BRANCH_CODE, // 40
136                 ///
137                 BOX_CODE
138         };
139
140         ///
141         enum {
142                 ///
143                 TEXT_TO_INSET_OFFSET = 2
144         };
145
146         ///
147         enum EDITABLE {
148                 ///
149                 NOT_EDITABLE = 0,
150                 ///
151                 IS_EDITABLE,
152                 ///
153                 HIGHLY_EDITABLE
154         };
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 std::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                           OutputParams const &) const = 0;
185         ///
186         virtual int plaintext(Buffer const &, std::ostream &,
187                           OutputParams const &) const = 0;
188         ///
189         virtual int linuxdoc(Buffer const &, std::ostream &,
190                              OutputParams const &) const = 0;
191         ///
192         virtual int docbook(Buffer const &, std::ostream &,
193                             OutputParams const &) 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         /// 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 int numParagraphs() const { return 0; }
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
244         /// used to toggle insets
245         // is the inset open?
246         virtual bool isOpen() const { return false; }
247         /// open the inset
248         virtual void open(BufferView *) {}
249         /// close the inset
250         virtual void close(BufferView *) const {}
251         /// check if the font of the char we want inserting is correct
252         /// and modify it if it is not.
253         virtual bool checkInsertChar(LyXFont &);
254         /// we need this here because collapsed insets are only EDITABLE
255         virtual void setFont(BufferView *, LyXFont const &,
256                          bool toggleall = false, bool selectall = false);
257
258         // should this inset be handled like a normal charater
259         virtual bool isChar() const { return false; }
260         // is this equivalent to a letter?
261         virtual bool isLetter() const { return false; }
262         // is this equivalent to a space (which is BTW different from
263         // a line separator)?
264         virtual bool isSpace() const { return false; }
265         // should we have a non-filled line before this inset?
266         virtual bool display() const { return false; }
267         // should we break lines after this inset?
268         virtual bool isLineSeparator() const { return false; }
269         // if this inset has paragraphs should they be output all as default
270         // paragraphs with "Standard" layout?
271         virtual bool forceDefaultParagraphs(InsetOld const *) const;
272         /** returns true if, when outputing LaTeX, font changes should
273             be closed before generating this inset. This is needed for
274             insets that may contain several paragraphs */
275         virtual bool noFontChange() const { return false; }
276         //
277         virtual void getDrawFont(LyXFont &) const {}
278         /* needed for widths which are % of something
279            returns the value of \textwidth in this inset. Most of the
280            time this is the width of the workarea, but if there is a
281            minipage somewhere, it will be the width of this minipage */
282         virtual int latexTextWidth(BufferView *) const;
283
284         /// mark the inset contents as erased (for change tracking)
285         virtual void markErased() {}
286
287         /// does this inset allows spellchecking?
288         virtual bool allowSpellCheck() const { return true; }
289
290         /** Adds a LaTeX snippet to the Preview Loader for transformation
291          *  into a bitmap image. Does not start the laoding process.
292          *
293          *  Most insets have no interest in this capability, so the method
294          *  defaults to empty.
295          */
296         virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
297 protected:
298         ///
299         mutable int top_x;
300         ///
301         mutable int top_baseline;
302         ///
303         mutable int scx;
304         /// Used to identify the inset for cursor positioning when undoing
305         unsigned int id_;
306         ///
307         mutable Dimension dim_;
308
309 private:
310         ///
311         UpdatableInset * owner_;
312         ///
313         std::string name_;
314         /** We store the LColor::color value as an int to get LColor.h out
315          *  of the header file.
316          */
317         int background_color_;
318 };
319
320
321 /** \c InsetOld_code is a wrapper for InsetOld::Code.
322  *  It can be forward-declared and passed as a function argument without
323  *  having to expose inset.h.
324  */
325 class InsetOld_code {
326         InsetOld::Code val_;
327 public:
328         InsetOld_code(InsetOld::Code val) : val_(val) {}
329         operator InsetOld::Code() const{ return val_; }
330 };
331
332
333 /**
334  * returns true if pointer argument is valid
335  * and points to an editable inset
336  */
337 bool isEditableInset(InsetOld const * i);
338
339
340 /**
341  * returns true if pointer argument is valid
342  * and points to a highly editable inset
343  */
344 bool isHighlyEditableInset(InsetOld const * i);
345
346 #endif