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 "dimension.h"
21 #include "support/types.h"
45 class InsetOld : public InsetBase {
47 /** This is not quite the correct place for this enum. I think
48 the correct would be to let each subclass of Inset declare
49 its own enum code. Actually the notion of an InsetOld::Code
50 should be avoided, but I am not sure how this could be done
56 TOC_CODE, // do these insets really need a code? (ale)
118 MATHMACRO_CODE, // 30
142 TEXT_TO_INSET_OFFSET = 2
156 typedef dispatch_result RESULT;
161 InsetOld(InsetOld const & in);
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(InsetOld::Code) const { return false; }
178 /// wrapper around the above
179 bool insetAllowed(InsetOld * 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 InsetOld::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 {}
237 /// returns the actuall scroll-value
238 virtual int scroll(bool recursive=true) const {
239 if (!recursive || !owner_)
244 /// try to get a inset pointer from it's id if we have
245 /// an inset to give back!
246 virtual InsetOld * getInsetFromID(int /*id*/) const { return 0; }
247 /// if this insets owns paragraphs (f.ex. InsetText) then it
248 /// should return it's very first one!
249 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
251 virtual bool haveParagraphs() const {
255 /// return the cursor if we own one otherwise giv'em just the
256 /// BufferView cursor to work with.
257 virtual LyXCursor const & cursor(BufferView * bview) const;
263 /// used to toggle insets
264 // is the inset open?
265 virtual bool isOpen() const { return false; }
267 virtual void open(BufferView *) {}
269 virtual void close(BufferView *) const {}
270 /// check if the font of the char we want inserting is correct
271 /// and modify it if it is not.
272 virtual bool checkInsertChar(LyXFont &);
273 /// we need this here because collapsed insets are only EDITABLE
274 virtual void setFont(BufferView *, LyXFont const &,
275 bool toggleall = false, bool selectall = false);
277 // needed for spellchecking text
279 virtual bool allowSpellcheck() const { return false; }
281 // should this inset be handled like a normal charater
282 virtual bool isChar() const { return false; }
283 // is this equivalent to a letter?
284 virtual bool isLetter() const { return false; }
285 // is this equivalent to a space (which is BTW different from
286 // a line separator)?
287 virtual bool isSpace() const { return false; }
288 // should we break lines after this inset?
289 virtual bool isLineSeparator() const { return false; }
290 // if this inset has paragraphs should they be output all as default
291 // paragraphs with "Standard" layout?
292 virtual bool forceDefaultParagraphs(InsetOld const *) const;
293 /** returns true if, when outputing LaTeX, font changes should
294 be closed before generating this inset. This is needed for
295 insets that may contain several paragraphs */
296 virtual bool noFontChange() const { return false; }
298 virtual void getDrawFont(LyXFont &) const {}
299 /* needed for widths which are % of something
300 returns the value of \textwidth in this inset. Most of the
301 time this is the width of the workarea, but if there is a
302 minipage somewhere, it will be the width of this minipage */
303 virtual int latexTextWidth(BufferView *) const;
305 /// mark the inset contents as erased (for change tracking)
306 virtual void markErased() {}
308 /** Adds a LaTeX snippet to the Preview Loader for transformation
309 * into a bitmap image. Does not start the laoding process.
311 * Most insets have no interest in this capability, so the method
314 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
316 /** Find the PreviewLoader, add a LaTeX snippet to it and
317 * start the loading process.
319 * Most insets have no interest in this capability, so the method
322 virtual void generatePreview() const {}
328 mutable int top_baseline;
331 /// Used to identify the inset for cursor positioning when undoing
334 static unsigned int inset_id;
336 mutable Dimension dim_;
340 UpdatableInset * owner_;
341 /// the paragraph in which this inset has been inserted
342 Paragraph * par_owner_;
346 LColor::color background_color_;
351 * returns true if pointer argument is valid
352 * and points to an editable inset
354 bool isEditableInset(InsetOld const * i);
358 * returns true if pointer argument is valid
359 * and points to a highly editable inset
361 bool isHighlyEditableInset(InsetOld const * i);