]> git.lyx.org Git - lyx.git/blob - src/insets/inset.h
remove Inset::getParagraphs()
[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 LyXLex;
29 class LyXText;
30 class Painter;
31 class Paragraph;
32 class UpdatableInset;
33
34 namespace lyx {
35 namespace graphics {
36         class PreviewLoader;
37 }
38 }
39
40 /// Insets
41 class InsetOld : public InsetBase {
42 public:
43         /** This is not quite the correct place for this enum. I think
44             the correct would be to let each subclass of Inset declare
45             its own enum code. Actually the notion of an InsetOld::Code
46             should be avoided, but I am not sure how this could be done
47             in a cleaner way. */
48         enum Code {
49                 ///
50                 NO_CODE, // 0
51                 ///
52                 TOC_CODE,  // do these insets really need a code? (ale)
53                 ///
54                 QUOTE_CODE,
55                 ///
56                 MARK_CODE,
57                 ///
58                 REF_CODE,
59                 ///
60                 URL_CODE, // 5
61                 ///
62                 HTMLURL_CODE,
63                 ///
64                 SEPARATOR_CODE,
65                 ///
66                 ENDING_CODE,
67                 ///
68                 LABEL_CODE,
69                 ///
70                 NOTE_CODE, // 10
71                 ///
72                 ACCENT_CODE,
73                 ///
74                 MATH_CODE,
75                 ///
76                 INDEX_CODE,
77                 ///
78                 INCLUDE_CODE,
79                 ///
80                 GRAPHICS_CODE, // 15
81                 ///
82                 BIBITEM_CODE,
83                 ///
84                 BIBTEX_CODE,
85                 ///
86                 TEXT_CODE,
87                 ///
88                 ERT_CODE,
89                 ///
90                 FOOT_CODE, // 20
91                 ///
92                 MARGIN_CODE,
93                 ///
94                 FLOAT_CODE,
95                 ///
96                 WRAP_CODE,
97                 ///
98                 MINIPAGE_CODE,
99                 ///
100                 SPACE_CODE, // 25
101                 ///
102                 SPECIALCHAR_CODE,
103                 ///
104                 TABULAR_CODE,
105                 ///
106                 EXTERNAL_CODE,
107 #if 0
108                 ///
109                 THEOREM_CODE,
110 #endif
111                 ///
112                 CAPTION_CODE,
113                 ///
114                 MATHMACRO_CODE, // 30
115                 ///
116                 ERROR_CODE,
117                 ///
118                 CITE_CODE,
119                 ///
120                 FLOAT_LIST_CODE,
121                 ///
122                 INDEX_PRINT_CODE,
123                 ///
124                 OPTARG_CODE, // 35
125                 ///
126                 ENVIRONMENT_CODE,
127                 ///
128                 HFILL_CODE,
129                 ///
130                 NEWLINE_CODE,
131                 ///
132                 LINE_CODE,
133                 ///
134                 BRANCH_CODE, // 40
135                 ///
136                 BOX_CODE,
137                 ///
138                 CHARSTYLE_CODE,
139                 ///
140                 VSPACE_CODE
141         };
142
143         ///
144         enum {
145                 ///
146                 TEXT_TO_INSET_OFFSET = 2
147         };
148
149         ///
150         enum EDITABLE {
151                 ///
152                 NOT_EDITABLE = 0,
153                 ///
154                 IS_EDITABLE,
155                 ///
156                 HIGHLY_EDITABLE
157         };
158
159         ///
160         InsetOld();
161         ///
162         InsetOld(InsetOld const & in);
163         ///
164         int ascent() const;
165         ///
166         int descent() const;
167         ///
168         int width() const;
169         /// what appears in the minibuffer when opening
170         virtual std::string const editMessage() const;
171         ///
172         virtual EDITABLE editable() const;
173         /// can we go further down on mouse click?
174         virtual bool descendable() const { return false; }
175         ///
176         virtual bool isTextInset() const { return false; }
177         /// return true if the inset should be removed automatically
178         virtual bool autoDelete() const;
179         /// returns true the inset can hold an inset of given type
180         virtual bool insetAllowed(InsetOld::Code) const { return false; }
181         /// wrapper around the above
182         bool insetAllowed(InsetOld * in) const;
183         ///
184         virtual void write(Buffer const &, std::ostream &) const = 0;
185         ///
186         virtual void read(Buffer const &, LyXLex & lex) = 0;
187         /// returns the number of rows (\n's) of generated tex code.
188         virtual int latex(Buffer const &, std::ostream &,
189                           OutputParams const &) const = 0;
190         ///
191         virtual int plaintext(Buffer const &, std::ostream &,
192                           OutputParams const &) const = 0;
193         ///
194         virtual int linuxdoc(Buffer const &, std::ostream &,
195                              OutputParams const &) const = 0;
196         ///
197         virtual int docbook(Buffer const &, std::ostream &,
198                             OutputParams const &) const = 0;
199
200         /// returns LyX code associated with the inset. Used for TOC, ...)
201         virtual InsetOld::Code lyxCode() const { return NO_CODE; }
202
203         /// returns true to override begin and end inset in file
204         virtual bool directWrite() const;
205
206         ///
207         void setInsetName(std::string const & s) { name_ = s; }
208         ///
209         std::string const & getInsetName() const { return name_; }
210         ///
211         void setOwner(UpdatableInset * inset) { owner_ = inset; }
212         ///
213         UpdatableInset * owner() const { return owner_; }
214         ///
215         virtual void setBackgroundColor(LColor_color);
216         ///
217         LColor_color backgroundColor() const;
218         ///
219         int x() const { return xo_; }
220         ///
221         int y() const { return yo_; }
222         /// returns the actual scroll-value
223         virtual int scroll(bool recursive = true) const;
224
225         /// if this insets owns text cells (e.g. InsetText) return cell num
226         virtual LyXText * getText(int /*num*/) const { return 0; }
227         ///
228         virtual int numParagraphs() const { return 0; }
229
230         /// used to toggle insets
231         // is the inset open?
232         virtual bool isOpen() const { return false; }
233         /// open the inset
234         virtual void open() {}
235         /// close the inset
236         virtual void close() {}
237         // should this inset be handled like a normal charater
238         virtual bool isChar() const { return false; }
239         // is this equivalent to a letter?
240         virtual bool isLetter() const { return false; }
241         // is this equivalent to a space (which is BTW different from
242         // a line separator)?
243         virtual bool isSpace() const { return false; }
244         // should we have a non-filled line before this inset?
245         virtual bool display() const { return false; }
246         // should we break lines after this inset?
247         virtual bool isLineSeparator() const { return false; }
248         // if this inset has paragraphs should they be output all as default
249         // paragraphs with "Standard" layout?
250         virtual bool forceDefaultParagraphs(InsetOld const *) const;
251         /** returns true if, when outputing LaTeX, font changes should
252             be closed before generating this inset. This is needed for
253             insets that may contain several paragraphs */
254         virtual bool noFontChange() const { return false; }
255
256         /// mark the inset contents as erased (for change tracking)
257         virtual void markErased() {}
258
259         /// does this inset allows spellchecking?
260         virtual bool allowSpellCheck() const { return true; }
261
262         /** Adds a LaTeX snippet to the Preview Loader for transformation
263          *  into a bitmap image. Does not start the laoding process.
264          *
265          *  Most insets have no interest in this capability, so the method
266          *  defaults to empty.
267          */
268         virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
269 protected:
270         ///
271         mutable int xo_;
272         ///
273         mutable int yo_;
274         ///
275         mutable int scx;
276         ///
277         mutable Dimension dim_;
278
279 private:
280         ///
281         UpdatableInset * owner_;
282         ///
283         std::string name_;
284         /** We store the LColor::color value as an int to get LColor.h out
285          *  of the header file.
286          */
287         int background_color_;
288 };
289
290
291 /** \c InsetOld_code is a wrapper for InsetOld::Code.
292  *  It can be forward-declared and passed as a function argument without
293  *  having to expose inset.h.
294  */
295 class InsetOld_code {
296         InsetOld::Code val_;
297 public:
298         InsetOld_code(InsetOld::Code val) : val_(val) {}
299         operator InsetOld::Code() const { return val_; }
300 };
301
302
303 /**
304  * returns true if pointer argument is valid
305  * and points to an editable inset
306  */
307 bool isEditableInset(InsetOld const * inset);
308
309
310 /**
311  * returns true if pointer argument is valid
312  * and points to a highly editable inset
313  */
314 bool isHighlyEditableInset(InsetOld const * inset);
315
316 #endif