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
19 #include "insetbase.h"
20 #include "support/types.h"
44 class Inset : public InsetBase {
46 /** This is not quite the correct place for this enum. I think
47 the correct would be to let each subclass of Inset declare
48 its own enum code. Actually the notion of an Inset::Code
49 should be avoided, but I am not sure how this could be done
55 TOC_CODE, // do these insets really need a code? (ale)
105 SPECIALCHAR_CODE, // 25
117 MATHMACRO_CODE, // 30
139 TEXT_TO_INSET_OFFSET = 2
153 typedef dispatch_result RESULT;
158 Inset(Inset const & in);
160 int ascent(BufferView *, LyXFont const &) const;
162 int descent(BufferView *, LyXFont const &) const;
164 int width(BufferView *, LyXFont const &) const;
165 /// what appears in the minibuffer when opening
166 virtual 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(Inset::Code) const { return false; }
175 /// wrapper around the above
176 bool insetAllowed(Inset * 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 Inset::Code lyxCode() const { return NO_CODE; }
195 /// returns true to override begin and end inset in file
196 virtual bool directWrite() const;
198 /// Returns true if the inset should be centered alone
199 virtual bool display() const { return false; }
200 /// Changes the display state of the inset
201 virtual void display(bool) {}
203 /// returns true if this inset needs a row on it's own
205 virtual bool needFullRow() const { return false; }
207 void setInsetName(string const & s) { name_ = s; }
209 string const & getInsetName() const { return name_; }
211 void setOwner(UpdatableInset * inset) { owner_ = inset; }
213 UpdatableInset * owner() const { return owner_; }
215 void parOwner(Paragraph * par) { par_owner_ = par; }
217 Paragraph * parOwner() const { return par_owner_; }
219 void setBackgroundColor(LColor::color);
221 LColor::color backgroundColor() const;
223 int x() const { return top_x; }
225 int y() const { return top_baseline; }
227 // because we could have fake text insets and have to call this
228 // inside them without cast!!!
230 virtual LyXText * getLyXText(BufferView const *,
231 bool recursive = false) const;
233 virtual void deleteLyXText(BufferView *, bool = true) const {}
235 virtual void resizeLyXText(BufferView *, bool /*force*/= false) const {}
236 /// returns the actuall scroll-value
237 virtual int scroll(bool recursive=true) const {
238 if (!recursive || !owner_)
243 /// try to get a inset pointer from it's id if we have
244 /// an inset to give back!
245 virtual Inset * getInsetFromID(int /*id*/) const { return 0; }
246 /// if this insets owns paragraphs (f.ex. InsetText) then it
247 /// should return it's very first one!
248 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
250 virtual bool haveParagraphs() const {
254 /// return the cursor if we own one otherwise giv'em just the
255 /// BufferView cursor to work with.
256 virtual LyXCursor const & cursor(BufferView * bview) const;
262 /// used to toggle insets
263 // is the inset open?
264 virtual bool isOpen() const { return false; }
266 virtual void open(BufferView *) {}
268 virtual void close(BufferView *) const {}
269 /// check if the font of the char we want inserting is correct
270 /// and modify it if it is not.
271 virtual bool checkInsertChar(LyXFont &);
272 /// we need this here because collapsed insets are only EDITABLE
273 virtual void setFont(BufferView *, LyXFont const &,
274 bool toggleall = false, bool selectall = false);
276 // needed for spellchecking text
278 virtual bool allowSpellcheck() const { return false; }
280 // should this inset be handled like a normal charater
281 virtual bool isChar() const { return false; }
282 // is this equivalent to a letter?
283 virtual bool isLetter() const { return false; }
284 // is this equivalent to a space (which is BTW different from
285 // a line separator)?
286 virtual bool isSpace() const { return false; }
287 // should we break lines after this inset?
288 virtual bool isLineSeparator() const { return false; }
289 // if this inset has paragraphs should they be output all as default
290 // paragraphs with "Standard" layout?
291 virtual bool forceDefaultParagraphs(Inset const *) const;
292 /** returns true if, when outputing LaTeX, font changes should
293 be closed before generating this inset. This is needed for
294 insets that may contain several paragraphs */
295 virtual bool noFontChange() const { return false; }
297 virtual void getDrawFont(LyXFont &) const {}
298 /* needed for widths which are % of something
299 returns the value of \textwidth in this inset. Most of the
300 time this is the width of the workarea, but if there is a
301 minipage somewhere, it will be the width of this minipage */
302 virtual int latexTextWidth(BufferView *) const;
304 /// mark the inset contents as erased (for change tracking)
305 virtual void markErased() {}
307 /** Adds a LaTeX snippet to the Preview Loader for transformation
308 * into a bitmap image. Does not start the laoding process.
310 * Most insets have no interest in this capability, so the method
313 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
315 /** Find the PreviewLoader, add a LaTeX snippet to it and
316 * start the loading process.
318 * Most insets have no interest in this capability, so the method
321 virtual void generatePreview() const {}
327 mutable int top_baseline;
333 static unsigned int inset_id;
337 UpdatableInset * owner_;
338 /// the paragraph in which this inset has been inserted
339 Paragraph * par_owner_;
343 LColor::color background_color_;
348 bool Inset::insetAllowed(Inset * in) const
350 return insetAllowed(in->lyxCode());
355 bool Inset::checkInsertChar(LyXFont &)
361 * returns true if pointer argument is valid
362 * and points to an editable inset
364 inline bool isEditableInset(Inset const * i)
366 return i && i->editable();
370 * returns true if pointer argument is valid
371 * and points to a highly editable inset
373 inline bool isHighlyEditableInset(Inset const * i)
375 return i && i->editable() == Inset::HIGHLY_EDITABLE;