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 /// update the inset representation
166 virtual void update(BufferView *, bool = false)
168 /// what appears in the minibuffer when opening
169 virtual string const editMessage() const;
171 virtual EDITABLE editable() const;
173 virtual bool isTextInset() const { return false; }
174 /// return true if the inset should be removed automatically
175 virtual bool autoDelete() const;
176 /// returns true the inset can hold an inset of given type
177 virtual bool insetAllowed(Inset::Code) const { return false; }
178 /// wrapper around the above
179 bool insetAllowed(Inset * in) const;
181 virtual void write(Buffer const *, std::ostream &) const = 0;
183 virtual void read(Buffer const *, LyXLex & lex) = 0;
184 /// returns the number of rows (\n's) of generated tex code.
185 virtual int latex(Buffer const *, std::ostream &,
186 LatexRunParams const &) const = 0;
188 virtual int ascii(Buffer const *,
189 std::ostream &, int linelen = 0) const = 0;
191 virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
193 virtual int docbook(Buffer const *, std::ostream &, bool) const = 0;
195 /// returns LyX code associated with the inset. Used for TOC, ...)
196 virtual Inset::Code lyxCode() const { return NO_CODE; }
198 /// returns true to override begin and end inset in file
199 virtual bool directWrite() const;
201 /// Returns true if the inset should be centered alone
202 virtual bool display() const { return false; }
203 /// Changes the display state of the inset
204 virtual void display(bool) {}
206 /// returns true if this inset needs a row on it's own
208 virtual bool needFullRow() const { return false; }
210 void setInsetName(string const & s) { name_ = s; }
212 string const & getInsetName() const { return name_; }
214 void setOwner(UpdatableInset * inset) { owner_ = inset; }
216 UpdatableInset * owner() const { return owner_; }
218 void parOwner(Paragraph * par) { par_owner_ = par; }
220 Paragraph * parOwner() const { return par_owner_; }
222 void setBackgroundColor(LColor::color);
224 LColor::color backgroundColor() const;
226 int x() const { return top_x; }
228 int y() const { return top_baseline; }
230 // because we could have fake text insets and have to call this
231 // inside them without cast!!!
233 virtual LyXText * getLyXText(BufferView const *,
234 bool recursive = false) const;
236 virtual void deleteLyXText(BufferView *, bool = true) const {}
238 virtual void resizeLyXText(BufferView *, bool /*force*/= false) const {}
239 /// returns the actuall scroll-value
240 virtual int scroll(bool recursive=true) const {
241 if (!recursive || !owner_)
246 /// try to get a inset pointer from it's id if we have
247 /// an inset to give back!
248 virtual Inset * getInsetFromID(int /*id*/) const { return 0; }
249 /// if this insets owns paragraphs (f.ex. InsetText) then it
250 /// should return it's very first one!
251 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
253 virtual bool haveParagraphs() const {
257 /// return the cursor if we own one otherwise giv'em just the
258 /// BufferView cursor to work with.
259 virtual LyXCursor const & cursor(BufferView * bview) const;
265 /// used to toggle insets
266 // is the inset open?
267 virtual bool isOpen() const { return false; }
269 virtual void open(BufferView *) {}
271 virtual void close(BufferView *) const {}
272 /// check if the font of the char we want inserting is correct
273 /// and modify it if it is not.
274 virtual bool checkInsertChar(LyXFont &);
275 /// we need this here because collapsed insets are only EDITABLE
276 virtual void setFont(BufferView *, LyXFont const &,
277 bool toggleall = false, bool selectall = false);
279 // needed for spellchecking text
281 virtual bool allowSpellcheck() const { return false; }
283 // should this inset be handled like a normal charater
284 virtual bool isChar() const { return false; }
285 // is this equivalent to a letter?
286 virtual bool isLetter() const { return false; }
287 // is this equivalent to a space (which is BTW different from
288 // a line separator)?
289 virtual bool isSpace() const { return false; }
290 // should we break lines after this inset?
291 virtual bool isLineSeparator() const { return false; }
292 // if this inset has paragraphs should they be output all as default
293 // paragraphs with "Standard" layout?
294 virtual bool forceDefaultParagraphs(Inset const *) const;
295 /** returns true if, when outputing LaTeX, font changes should
296 be closed before generating this inset. This is needed for
297 insets that may contain several paragraphs */
298 virtual bool noFontChange() const { return false; }
300 virtual void getDrawFont(LyXFont &) const {}
301 /* needed for widths which are % of something
302 returns the value of \textwidth in this inset. Most of the
303 time this is the width of the workarea, but if there is a
304 minipage somewhere, it will be the width of this minipage */
305 virtual int latexTextWidth(BufferView *) const;
307 /// mark the inset contents as erased (for change tracking)
308 virtual void markErased() {}
310 /** Adds a LaTeX snippet to the Preview Loader for transformation
311 * into a bitmap image. Does not start the laoding process.
313 * Most insets have no interest in this capability, so the method
316 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
318 /** Find the PreviewLoader, add a LaTeX snippet to it and
319 * start the loading process.
321 * Most insets have no interest in this capability, so the method
324 virtual void generatePreview() const {}
330 mutable int top_baseline;
336 static unsigned int inset_id;
340 UpdatableInset * owner_;
341 /// the paragraph in which this inset has been inserted
342 Paragraph * par_owner_;
346 LColor::color background_color_;
351 bool Inset::insetAllowed(Inset * in) const
353 return insetAllowed(in->lyxCode());
358 bool Inset::checkInsertChar(LyXFont &)
364 * returns true if pointer argument is valid
365 * and points to an editable inset
367 inline bool isEditableInset(Inset const * i)
369 return i && i->editable();
373 * returns true if pointer argument is valid
374 * and points to a highly editable inset
376 inline bool isHighlyEditableInset(Inset const * i)
378 return i && i->editable() == Inset::HIGHLY_EDITABLE;