]> git.lyx.org Git - features.git/blob - src/insets/inset.h
Part of IU.
[features.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
21 class Buffer;
22 class LColor_color;
23 class FuncRequest;
24 class OutputParams;
25 class CursorSlice;
26 class LyXLex;
27 class LyXText;
28 class Painter;
29 class Paragraph;
30 class UpdatableInset;
31
32 namespace lyx {
33 namespace graphics {
34         class PreviewLoader;
35 }
36 }
37
38
39 /// Insets
40 class InsetOld : public InsetBase {
41 public:
42         ///
43         enum {
44                 ///
45                 TEXT_TO_INSET_OFFSET = 2
46         };
47
48         ///
49         enum EDITABLE {
50                 ///
51                 NOT_EDITABLE = 0,
52                 ///
53                 IS_EDITABLE,
54                 ///
55                 HIGHLY_EDITABLE
56         };
57
58         ///
59         InsetOld();
60         ///
61         InsetOld(InsetOld const & in);
62         ///
63         int ascent() const;
64         ///
65         int descent() const;
66         ///
67         int width() const;
68         /// what appears in the minibuffer when opening
69         virtual std::string const editMessage() const;
70         ///
71         virtual EDITABLE editable() const;
72         /// can we go further down on mouse click?
73         virtual bool descendable() const { return false; }
74         ///
75         virtual bool isTextInset() const { return false; }
76         /// return true if the inset should be removed automatically
77         virtual bool autoDelete() const;
78         /// returns true the inset can hold an inset of given type
79         virtual bool insetAllowed(InsetOld::Code) const { return false; }
80         /// wrapper around the above
81         bool insetAllowed(InsetOld * in) const;
82         ///
83         virtual void write(Buffer const &, std::ostream &) const = 0;
84         ///
85         virtual void read(Buffer const &, LyXLex & lex) = 0;
86         /// returns the number of rows (\n's) of generated tex code.
87         virtual int latex(Buffer const &, std::ostream &,
88                           OutputParams const &) const = 0;
89         ///
90         virtual int plaintext(Buffer const &, std::ostream &,
91                           OutputParams const &) const = 0;
92         ///
93         virtual int linuxdoc(Buffer const &, std::ostream &,
94                              OutputParams const &) const = 0;
95         ///
96         virtual int docbook(Buffer const &, std::ostream &,
97                             OutputParams const &) const = 0;
98
99         /// returns true to override begin and end inset in file
100         virtual bool directWrite() const;
101
102         ///
103         void setInsetName(std::string const & s) { name_ = s; }
104         ///
105         std::string const & getInsetName() const { return name_; }
106         ///
107         void setOwner(UpdatableInset * inset) { owner_ = inset; }
108         ///
109         UpdatableInset * owner() const { return owner_; }
110         ///
111         virtual void setBackgroundColor(LColor_color);
112         ///
113         LColor_color backgroundColor() const;
114         ///
115         int x() const { return xo_; }
116         ///
117         int y() const { return yo_; }
118         /// returns the actual scroll-value
119         virtual int scroll(bool recursive = true) const;
120
121         /// if this insets owns text cells (e.g. InsetText) return cell num
122         virtual LyXText * getText(int /*num*/) const { return 0; }
123         ///
124         virtual int numParagraphs() const { return 0; }
125         /// returns cell covering position (x,y), -1 if none exists
126         virtual int getCell(int x, int y) const;
127
128         /// used to toggle insets
129         // is the inset open?
130         virtual bool isOpen() const { return false; }
131         /// open the inset
132         virtual void open() {}
133         /// close the inset
134         virtual void close() {}
135         // should this inset be handled like a normal charater
136         virtual bool isChar() const { return false; }
137         // is this equivalent to a letter?
138         virtual bool isLetter() const { return false; }
139         // is this equivalent to a space (which is BTW different from
140         // a line separator)?
141         virtual bool isSpace() const { return false; }
142         // should we have a non-filled line before this inset?
143         virtual bool display() const { return false; }
144         // should we break lines after this inset?
145         virtual bool isLineSeparator() const { return false; }
146         // if this inset has paragraphs should they be output all as default
147         // paragraphs with "Standard" layout?
148         virtual bool forceDefaultParagraphs(InsetOld const *) const;
149         /** returns true if, when outputing LaTeX, font changes should
150             be closed before generating this inset. This is needed for
151             insets that may contain several paragraphs */
152         virtual bool noFontChange() const { return false; }
153
154         /// mark the inset contents as erased (for change tracking)
155         virtual void markErased() {}
156
157         /// does this inset allows spellchecking?
158         virtual bool allowSpellCheck() const { return true; }
159
160         /** Adds a LaTeX snippet to the Preview Loader for transformation
161          *  into a bitmap image. Does not start the laoding process.
162          *
163          *  Most insets have no interest in this capability, so the method
164          *  defaults to empty.
165          */
166         virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
167 protected:
168         ///
169         mutable int xo_;
170         ///
171         mutable int yo_;
172         ///
173         mutable int scx;
174         ///
175         mutable Dimension dim_;
176
177 private:
178         ///
179         UpdatableInset * owner_;
180         ///
181         std::string name_;
182         /** We store the LColor::color value as an int to get LColor.h out
183          *  of the header file.
184          */
185         int background_color_;
186 };
187
188
189 /** \c InsetOld_code is a wrapper for InsetOld::Code.
190  *  It can be forward-declared and passed as a function argument without
191  *  having to expose inset.h.
192  */
193 class InsetOld_code {
194         InsetOld::Code val_;
195 public:
196         InsetOld_code(InsetOld::Code val) : val_(val) {}
197         operator InsetOld::Code() const { return val_; }
198 };
199
200
201 /**
202  * returns true if pointer argument is valid
203  * and points to an editable inset
204  */
205 bool isEditableInset(InsetOld const * inset);
206
207
208 /**
209  * returns true if pointer argument is valid
210  * and points to a highly editable inset
211  */
212 bool isHighlyEditableInset(InsetOld const * inset);
213
214 #endif