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
20 #include "insetbase.h"
21 #include "support/types.h"
43 class Inset : 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 Inset::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)
104 SPECIALCHAR_CODE, // 25
116 MATHMACRO_CODE, // 30
138 TEXT_TO_INSET_OFFSET = 2
152 typedef dispatch_result RESULT;
157 Inset(Inset const & in);
159 int ascent(BufferView *, LyXFont const &) const;
161 int descent(BufferView *, LyXFont const &) const;
163 int width(BufferView *, LyXFont const &) const;
164 /// update the inset representation
165 virtual void update(BufferView *, bool = false)
167 /// what appears in the minibuffer when opening
168 virtual string const editMessage() const;
170 virtual EDITABLE editable() const;
172 virtual bool isTextInset() const { return false; }
173 /// return true if the inset should be removed automatically
174 virtual bool autoDelete() const;
175 /// returns true the inset can hold an inset of given type
176 virtual bool insetAllowed(Inset::Code) const { return false; }
177 /// wrapper around the above
178 bool insetAllowed(Inset * in) const;
180 virtual void write(Buffer const *, std::ostream &) const = 0;
182 virtual void read(Buffer const *, LyXLex & lex) = 0;
183 /// returns the number of rows (\n's) of generated tex code.
184 virtual int latex(Buffer const *, std::ostream &,
185 LatexRunParams const &) const = 0;
187 virtual int ascii(Buffer const *,
188 std::ostream &, int linelen = 0) const = 0;
190 virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
192 virtual int docbook(Buffer const *, std::ostream &, bool) const = 0;
194 /// returns LyX code associated with the inset. Used for TOC, ...)
195 virtual Inset::Code lyxCode() const { return NO_CODE; }
197 virtual std::vector<string> const getLabelList() const {
198 return std::vector<string>();
202 virtual Inset * clone() const = 0;
204 /// returns true to override begin and end inset in file
205 virtual bool directWrite() const;
207 /// Returns true if the inset should be centered alone
208 virtual bool display() const { return false; }
209 /// Changes the display state of the inset
210 virtual void display(bool) {}
212 /// returns true if this inset needs a row on it's own
214 virtual bool needFullRow() const { return false; }
216 void setInsetName(string const & s) { name_ = s; }
218 string const & getInsetName() const { return name_; }
220 void setOwner(UpdatableInset * inset) { owner_ = inset; }
222 UpdatableInset * owner() const { return owner_; }
224 void parOwner(Paragraph * par) { par_owner_ = par; }
226 Paragraph * parOwner() const { return par_owner_; }
228 void setBackgroundColor(LColor::color);
230 LColor::color backgroundColor() const;
232 int x() const { return top_x; }
234 int y() const { return top_baseline; }
236 // because we could have fake text insets and have to call this
237 // inside them without cast!!!
239 virtual LyXText * getLyXText(BufferView const *,
240 bool const recursive = false) const;
242 virtual void deleteLyXText(BufferView *, bool = true) const {}
244 virtual void resizeLyXText(BufferView *, bool /*force*/= false) const {}
245 /// returns the actuall scroll-value
246 virtual int scroll(bool recursive=true) const {
247 if (!recursive || !owner_)
252 /// try to get a inset pointer from it's id if we have
253 /// an inset to give back!
254 virtual Inset * getInsetFromID(int /*id*/) const { return 0; }
255 /// if this insets owns paragraphs (f.ex. InsetText) then it
256 /// should return it's very first one!
257 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
259 virtual bool haveParagraphs() const {
263 /// return the cursor if we own one otherwise giv'em just the
264 /// BufferView cursor to work with.
265 virtual LyXCursor const & cursor(BufferView * bview) const;
271 /// used to toggle insets
272 // is the inset open?
273 virtual bool isOpen() const { return false; }
275 virtual void open(BufferView *) {}
277 virtual void close(BufferView *) const {}
278 /// check if the font of the char we want inserting is correct
279 /// and modify it if it is not.
280 virtual bool checkInsertChar(LyXFont &);
281 /// we need this here because collapsed insets are only EDITABLE
282 virtual void setFont(BufferView *, LyXFont const &,
283 bool toggleall = false, bool selectall = false);
285 // needed for spellchecking text
287 virtual bool allowSpellcheck() const { return false; }
289 // should this inset be handled like a normal charater
290 virtual bool isChar() const { return false; }
291 // is this equivalent to a letter?
292 virtual bool isLetter() const { return false; }
293 // is this equivalent to a space (which is BTW different from
294 // a line separator)?
295 virtual bool isSpace() const { return false; }
296 // should we break lines after this inset?
297 virtual bool isLineSeparator() const { return false; }
298 // if this inset has paragraphs should they be output all as default
299 // paragraphs with "Standard" layout?
300 virtual bool forceDefaultParagraphs(Inset const *) const;
301 /** returns true if, when outputing LaTeX, font changes should
302 be closed before generating this inset. This is needed for
303 insets that may contain several paragraphs */
304 virtual bool noFontChange() const { return false; }
306 virtual void getDrawFont(LyXFont &) const {}
307 /* needed for widths which are % of something
308 returns the value of \textwidth in this inset. Most of the
309 time this is the width of the workarea, but if there is a
310 minipage somewhere, it will be the width of this minipage */
311 virtual int latexTextWidth(BufferView *) const;
313 /// mark the inset contents as erased (for change tracking)
314 virtual void markErased() {}
316 /** Adds a LaTeX snippet to the Preview Loader for transformation
317 * into a bitmap image. Does not start the laoding process.
319 * Most insets have no interest in this capability, so the method
322 virtual void addPreview(grfx::PreviewLoader &) const {}
324 /** Find the PreviewLoader, add a LaTeX snippet to it and
325 * start the loading process.
327 * Most insets have no interest in this capability, so the method
330 virtual void generatePreview() const {}
336 mutable int top_baseline;
342 static unsigned int inset_id;
346 UpdatableInset * owner_;
347 /// the paragraph in which this inset has been inserted
348 Paragraph * par_owner_;
352 LColor::color background_color_;
357 bool Inset::insetAllowed(Inset * in) const
359 return insetAllowed(in->lyxCode());
364 bool Inset::checkInsertChar(LyXFont &)
370 * returns true if pointer argument is valid
371 * and points to an editable inset
373 inline bool isEditableInset(Inset const * i)
375 return i && i->editable();
379 * returns true if pointer argument is valid
380 * and points to a highly editable inset
382 inline bool isHighlyEditableInset(Inset const * i)
384 return i && i->editable() == Inset::HIGHLY_EDITABLE;