]> git.lyx.org Git - lyx.git/blob - src/insets/inset.h
setFont rework + some code simplification
[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                 CHARSTYLE_CODE
140         };
141
142         ///
143         enum {
144                 ///
145                 TEXT_TO_INSET_OFFSET = 2
146         };
147
148         ///
149         enum EDITABLE {
150                 ///
151                 NOT_EDITABLE = 0,
152                 ///
153                 IS_EDITABLE,
154                 ///
155                 HIGHLY_EDITABLE
156         };
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         /// can we go further down on mouse click?
173         virtual bool descendable() const { return false; }
174         ///
175         virtual bool isTextInset() const { return false; }
176         /// return true if the inset should be removed automatically
177         virtual bool autoDelete() const;
178         /// returns true the inset can hold an inset of given type
179         virtual bool insetAllowed(InsetOld::Code) const { return false; }
180         /// wrapper around the above
181         bool insetAllowed(InsetOld * in) const;
182         ///
183         virtual void write(Buffer const &, std::ostream &) const = 0;
184         ///
185         virtual void read(Buffer const &, LyXLex & lex) = 0;
186         /// returns the number of rows (\n's) of generated tex code.
187         virtual int latex(Buffer const &, std::ostream &,
188                           OutputParams const &) const = 0;
189         ///
190         virtual int plaintext(Buffer const &, std::ostream &,
191                           OutputParams const &) const = 0;
192         ///
193         virtual int linuxdoc(Buffer const &, std::ostream &,
194                              OutputParams const &) const = 0;
195         ///
196         virtual int docbook(Buffer const &, std::ostream &,
197                             OutputParams const &) const = 0;
198
199         /// returns LyX code associated with the inset. Used for TOC, ...)
200         virtual InsetOld::Code lyxCode() const { return NO_CODE; }
201
202         /// returns true to override begin and end inset in file
203         virtual bool directWrite() const;
204
205         ///
206         void setInsetName(std::string const & s) { name_ = s; }
207         ///
208         std::string const & getInsetName() const { return name_; }
209         ///
210         void setOwner(UpdatableInset * inset) { owner_ = inset; }
211         ///
212         UpdatableInset * owner() const { return owner_; }
213         ///
214         void setBackgroundColor(LColor_color);
215         ///
216         LColor_color backgroundColor() const;
217         ///
218         int x() const { return xo_; }
219         ///
220         int y() const { return yo_; }
221         /// returns the actual scroll-value
222         virtual int scroll(bool recursive = true) const;
223
224         /// if this insets owns paragraphs (f.ex. InsetText) then it
225         /// should return it's very first one!
226         virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
227         ///
228         virtual LyXText * getText(int /*num*/) const { return 0; }
229         ///
230         virtual int numParagraphs() const { return 0; }
231
232         /// used to toggle insets
233         // is the inset open?
234         virtual bool isOpen() const { return false; }
235         /// open the inset
236         virtual void open() {}
237         /// close the inset
238         virtual void close() const {}
239         /// check if the font of the char we want inserting is correct
240         /// and modify it if it is not.
241         virtual bool checkInsertChar(LyXFont &);
242         // should this inset be handled like a normal charater
243         virtual bool isChar() const { return false; }
244         // is this equivalent to a letter?
245         virtual bool isLetter() const { return false; }
246         // is this equivalent to a space (which is BTW different from
247         // a line separator)?
248         virtual bool isSpace() const { return false; }
249         // should we have a non-filled line before this inset?
250         virtual bool display() const { return false; }
251         // should we break lines after this inset?
252         virtual bool isLineSeparator() const { return false; }
253         // if this inset has paragraphs should they be output all as default
254         // paragraphs with "Standard" layout?
255         virtual bool forceDefaultParagraphs(InsetOld const *) const;
256         /** returns true if, when outputing LaTeX, font changes should
257             be closed before generating this inset. This is needed for
258             insets that may contain several paragraphs */
259         virtual bool noFontChange() const { return false; }
260         //
261         virtual void getDrawFont(LyXFont &) const {}
262         /* needed for widths which are % of something
263            returns the value of \textwidth in this inset. Most of the
264            time this is the width of the workarea, but if there is a
265            minipage somewhere, it will be the width of this minipage */
266         virtual int latexTextWidth(BufferView *) const;
267
268         /// mark the inset contents as erased (for change tracking)
269         virtual void markErased() {}
270
271         /// does this inset allows spellchecking?
272         virtual bool allowSpellCheck() const { return true; }
273
274         /** Adds a LaTeX snippet to the Preview Loader for transformation
275          *  into a bitmap image. Does not start the laoding process.
276          *
277          *  Most insets have no interest in this capability, so the method
278          *  defaults to empty.
279          */
280         virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
281 protected:
282         ///
283         mutable int xo_;
284         ///
285         mutable int yo_;
286         ///
287         mutable int scx;
288         ///
289         mutable Dimension dim_;
290
291 private:
292         ///
293         UpdatableInset * owner_;
294         ///
295         std::string name_;
296         /** We store the LColor::color value as an int to get LColor.h out
297          *  of the header file.
298          */
299         int background_color_;
300 };
301
302
303 /** \c InsetOld_code is a wrapper for InsetOld::Code.
304  *  It can be forward-declared and passed as a function argument without
305  *  having to expose inset.h.
306  */
307 class InsetOld_code {
308         InsetOld::Code val_;
309 public:
310         InsetOld_code(InsetOld::Code val) : val_(val) {}
311         operator InsetOld::Code() const { return val_; }
312 };
313
314
315 /**
316  * returns true if pointer argument is valid
317  * and points to an editable inset
318  */
319 bool isEditableInset(InsetOld const * inset);
320
321
322 /**
323  * returns true if pointer argument is valid
324  * and points to a highly editable inset
325  */
326 bool isHighlyEditableInset(InsetOld const * inset);
327
328 #endif