4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
9 * \author Lars Gullik Bjønnes
10 * \author Matthias Ettrich
12 * Full author contact details are available in file CREDITS.
18 #include "insetbase.h"
19 #include "dimension.h"
20 #include "ParagraphList_fwd.h"
43 class InsetOld : public InsetBase {
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
54 TOC_CODE, // do these insets really need a code? (ale)
116 MATHMACRO_CODE, // 30
142 TEXT_TO_INSET_OFFSET = 2
158 InsetOld(InsetOld const & in);
165 /// what appears in the minibuffer when opening
166 virtual std::string const editMessage() const;
168 virtual EDITABLE editable() const;
170 virtual bool isTextInset() const { return false; }
171 /// return true if the inset should be removed automatically
172 virtual bool autoDelete() const;
173 /// returns true the inset can hold an inset of given type
174 virtual bool insetAllowed(InsetOld::Code) const { return false; }
175 /// wrapper around the above
176 bool insetAllowed(InsetOld * in) const;
178 virtual void write(Buffer const &, std::ostream &) const = 0;
180 virtual void read(Buffer const &, LyXLex & lex) = 0;
181 /// returns the number of rows (\n's) of generated tex code.
182 virtual int latex(Buffer const &, std::ostream &,
183 LatexRunParams const &) const = 0;
185 virtual int ascii(Buffer const &,
186 std::ostream &, int linelen = 0) const = 0;
188 virtual int linuxdoc(Buffer const &, std::ostream &) const = 0;
190 virtual int docbook(Buffer const &, std::ostream &, bool) const = 0;
192 /// returns LyX code associated with the inset. Used for TOC, ...)
193 virtual InsetOld::Code lyxCode() const { return NO_CODE; }
195 /// returns true to override begin and end inset in file
196 virtual bool directWrite() const;
199 void setInsetName(std::string const & s) { name_ = s; }
201 std::string const & getInsetName() const { return name_; }
203 void setOwner(UpdatableInset * inset) { owner_ = inset; }
205 UpdatableInset * owner() const { return owner_; }
207 void setBackgroundColor(LColor_color);
209 LColor_color backgroundColor() const;
211 int x() const { return top_x; }
213 int y() const { return top_baseline; }
215 // because we could have fake text insets and have to call this
216 // inside them without cast!!!
218 virtual LyXText * getLyXText(BufferView const *,
219 bool recursive = false) const;
221 virtual void deleteLyXText(BufferView *, bool = true) const {}
222 /// returns the actuall scroll-value
223 virtual int scroll(bool recursive=true) const {
224 if (!recursive || !owner_)
229 /// try to get a inset pointer from it's id if we have
230 /// an inset to give back!
231 virtual InsetOld * getInsetFromID(int /*id*/) const { return 0; }
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; }
236 virtual LyXText * getText(int /*num*/) const { return 0; }
238 virtual bool haveParagraphs() const {
242 /// return the cursor if we own one otherwise giv'em just the
243 /// BufferView cursor to work with.
244 virtual LyXCursor const & cursor(BufferView * bview) const;
249 /// lock cell with given index
250 virtual void edit(BufferView *, int /*index*/) {}
252 /// used to toggle insets
253 // is the inset open?
254 virtual bool isOpen() const { return false; }
256 virtual void open(BufferView *) {}
258 virtual void close(BufferView *) const {}
259 /// check if the font of the char we want inserting is correct
260 /// and modify it if it is not.
261 virtual bool checkInsertChar(LyXFont &);
262 /// we need this here because collapsed insets are only EDITABLE
263 virtual void setFont(BufferView *, LyXFont const &,
264 bool toggleall = false, bool selectall = false);
266 // needed for spellchecking text
268 virtual bool allowSpellcheck() const { return false; }
270 // should this inset be handled like a normal charater
271 virtual bool isChar() const { return false; }
272 // is this equivalent to a letter?
273 virtual bool isLetter() const { return false; }
274 // is this equivalent to a space (which is BTW different from
275 // a line separator)?
276 virtual bool isSpace() const { return false; }
277 // should we break lines after this inset?
278 virtual bool isLineSeparator() const { return false; }
279 // if this inset has paragraphs should they be output all as default
280 // paragraphs with "Standard" layout?
281 virtual bool forceDefaultParagraphs(InsetOld const *) const;
282 /** returns true if, when outputing LaTeX, font changes should
283 be closed before generating this inset. This is needed for
284 insets that may contain several paragraphs */
285 virtual bool noFontChange() const { return false; }
287 virtual void getDrawFont(LyXFont &) const {}
288 /* needed for widths which are % of something
289 returns the value of \textwidth in this inset. Most of the
290 time this is the width of the workarea, but if there is a
291 minipage somewhere, it will be the width of this minipage */
292 virtual int latexTextWidth(BufferView *) const;
294 /// mark the inset contents as erased (for change tracking)
295 virtual void markErased() {}
297 /** Adds a LaTeX snippet to the Preview Loader for transformation
298 * into a bitmap image. Does not start the laoding process.
300 * Most insets have no interest in this capability, so the method
303 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
308 mutable int top_baseline;
311 /// Used to identify the inset for cursor positioning when undoing
314 static unsigned int inset_id;
316 mutable Dimension dim_;
320 UpdatableInset * owner_;
323 /** We store the LColor::color value as an int to get LColor.h out
324 * of the header file.
326 int background_color_;
330 /** \c InsetOld_code is a wrapper for InsetOld::Code.
331 * It can be forward-declared and passed as a function argument without
332 * having to expose inset.h.
334 class InsetOld_code {
337 InsetOld_code(InsetOld::Code val) : val_(val) {}
338 operator InsetOld::Code() const{ return val_; }
343 * returns true if pointer argument is valid
344 * and points to an editable inset
346 bool isEditableInset(InsetOld const * i);
350 * returns true if pointer argument is valid
351 * and points to a highly editable inset
353 bool isHighlyEditableInset(InsetOld const * i);