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