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"
42 class Inset : public InsetBase {
44 /** This is not quite the correct place for this enum. I think
45 the correct would be to let each subclass of Inset declare
46 its own enum code. Actually the notion of an Inset::Code
47 should be avoided, but I am not sure how this could be done
53 TOC_CODE, // do these insets really need a code? (ale)
103 SPECIALCHAR_CODE, // 25
115 MATHMACRO_CODE, // 30
137 TEXT_TO_INSET_OFFSET = 2
151 typedef dispatch_result RESULT;
156 Inset(Inset const & in);
158 int ascent(BufferView *, LyXFont const &) const;
160 int descent(BufferView *, LyXFont const &) const;
162 int width(BufferView *, LyXFont const &) const;
163 /// update the inset representation
164 virtual void update(BufferView *, bool = false)
166 /// what appears in the minibuffer when opening
167 virtual string const editMessage() const;
169 virtual EDITABLE editable() const;
171 virtual bool isTextInset() const { return false; }
172 /// return true if the inset should be removed automatically
173 virtual bool autoDelete() const;
174 /// returns true the inset can hold an inset of given type
175 virtual bool insetAllowed(Inset::Code) const { return false; }
176 /// wrapper around the above
177 bool insetAllowed(Inset * in) const;
179 virtual void write(Buffer const *, std::ostream &) const = 0;
181 virtual void read(Buffer const *, LyXLex & lex) = 0;
182 /// returns the number of rows (\n's) of generated tex code.
183 virtual int latex(Buffer const *, std::ostream &,
184 LatexRunParams const &) const = 0;
186 virtual int ascii(Buffer const *,
187 std::ostream &, int linelen = 0) const = 0;
189 virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
191 virtual int docbook(Buffer const *, std::ostream &, bool) const = 0;
193 /// returns LyX code associated with the inset. Used for TOC, ...)
194 virtual Inset::Code lyxCode() const { return NO_CODE; }
196 virtual std::vector<string> const getLabelList() const {
197 return std::vector<string>();
201 virtual Inset * clone(Buffer const &) const = 0;
203 /// returns true to override begin and end inset in file
204 virtual bool directWrite() const;
206 /// Returns true if the inset should be centered alone
207 virtual bool display() const { return false; }
208 /// Changes the display state of the inset
209 virtual void display(bool) {}
211 /// returns true if this inset needs a row on it's own
213 virtual bool needFullRow() const { return false; }
215 void setInsetName(string const & s) { name_ = s; }
217 string const & getInsetName() const { return name_; }
219 void setOwner(Inset * inset) { owner_ = inset; }
221 Inset * owner() const { return owner_; }
223 void parOwner(Paragraph * par) { par_owner_ = par; }
225 Paragraph * parOwner() const { return par_owner_; }
227 void setBackgroundColor(LColor::color);
229 LColor::color backgroundColor() const;
231 int x() const { return top_x; }
233 int y() const { return top_baseline; }
235 // because we could have fake text insets and have to call this
236 // inside them without cast!!!
238 virtual LyXText * getLyXText(BufferView const *,
239 bool const recursive = false) const;
241 virtual void deleteLyXText(BufferView *, bool = true) const {}
243 virtual void resizeLyXText(BufferView *, bool /*force*/= false) const {}
244 /// returns the actuall scroll-value
245 virtual int scroll(bool recursive=true) const {
246 if (!recursive || !owner_)
251 /// try to get a inset pointer from it's id if we have
252 /// an inset to give back!
253 virtual Inset * getInsetFromID(int /*id*/) const { return 0; }
254 /// if this insets owns paragraphs (f.ex. InsetText) then it
255 /// should return it's very first one!
256 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
258 virtual bool haveParagraphs() const {
262 /// return the cursor if we own one otherwise giv'em just the
263 /// BufferView cursor to work with.
264 virtual LyXCursor const & cursor(BufferView * bview) const;
270 /// used to toggle insets
271 // is the inset open?
272 virtual bool isOpen() const { return false; }
274 virtual void open(BufferView *) {}
276 virtual void close(BufferView *) const {}
277 /// check if the font of the char we want inserting is correct
278 /// and modify it if it is not.
279 virtual bool checkInsertChar(LyXFont &);
280 /// we need this here because collapsed insets are only EDITABLE
281 virtual void setFont(BufferView *, LyXFont const &,
282 bool toggleall = false, bool selectall = false);
284 // needed for spellchecking text
286 virtual bool allowSpellcheck() const { return false; }
288 // should this inset be handled like a normal charater
289 virtual bool isChar() const { return false; }
290 // is this equivalent to a letter?
291 virtual bool isLetter() const { return false; }
292 // is this equivalent to a space (which is BTW different from
293 // a line separator)?
294 virtual bool isSpace() const { return false; }
295 // should we break lines after this inset?
296 virtual bool isLineSeparator() const { return false; }
297 // if this inset has paragraphs should they be output all as default
298 // paragraphs with "Standard" layout?
299 virtual bool forceDefaultParagraphs(Inset const *) const;
300 /** returns true if, when outputing LaTeX, font changes should
301 be closed before generating this inset. This is needed for
302 insets that may contain several paragraphs */
303 virtual bool noFontChange() const { return false; }
305 virtual void getDrawFont(LyXFont &) const {}
306 /* needed for widths which are % of something
307 returns the value of \textwidth in this inset. Most of the
308 time this is the width of the workarea, but if there is a
309 minipage somewhere, it will be the width of this minipage */
310 virtual int latexTextWidth(BufferView *) const;
312 /// mark the inset contents as erased (for change tracking)
313 virtual void markErased() {}
315 /** Adds a LaTeX snippet to the Preview Loader for transformation
316 * into a bitmap image. Does not start the laoding process.
318 * Most insets have no interest in this capability, so the method
321 virtual void addPreview(grfx::PreviewLoader &) const {}
323 /** Find the PreviewLoader, add a LaTeX snippet to it and
324 * start the loading process.
326 * Most insets have no interest in this capability, so the method
329 virtual void generatePreview() const {}
335 mutable int top_baseline;
341 static unsigned int inset_id;
346 /// the paragraph in which this inset has been inserted
347 Paragraph * par_owner_;
351 LColor::color background_color_;
356 bool Inset::insetAllowed(Inset * in) const
358 return insetAllowed(in->lyxCode());
363 bool Inset::checkInsertChar(LyXFont &)
369 * returns true if pointer argument is valid
370 * and points to an editable inset
372 inline bool isEditableInset(Inset const * i)
374 return i && i->editable();
378 * returns true if pointer argument is valid
379 * and points to a highly editable inset
381 inline bool isHighlyEditableInset(Inset const * i)
383 return i && i->editable() == Inset::HIGHLY_EDITABLE;