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.
18 #include "insetbase.h"
19 #include "dimension.h"
20 #include "ParagraphList_fwd.h"
43 class InsetOld : 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 InsetOld::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)
116 MATHMACRO_CODE, // 30
144 TEXT_TO_INSET_OFFSET = 2
160 InsetOld(InsetOld const & in);
167 /// what appears in the minibuffer when opening
168 virtual std::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(InsetOld::Code) const { return false; }
177 /// wrapper around the above
178 bool insetAllowed(InsetOld * 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 InsetOld::Code lyxCode() const { return NO_CODE; }
197 /// returns true to override begin and end inset in file
198 virtual bool directWrite() const;
201 void setInsetName(std::string const & s) { name_ = s; }
203 std::string const & getInsetName() const { return name_; }
205 void setOwner(UpdatableInset * inset) { owner_ = inset; }
207 UpdatableInset * owner() const { return owner_; }
209 void setBackgroundColor(LColor_color);
211 LColor_color backgroundColor() const;
213 int x() const { return top_x; }
215 int y() const { return top_baseline; }
217 // because we could have fake text insets and have to call this
218 // inside them without cast!!!
220 virtual LyXText * getLyXText(BufferView const *,
221 bool recursive = false) const;
223 virtual void deleteLyXText(BufferView *, bool = true) const {}
224 /// returns the actuall scroll-value
225 virtual int scroll(bool recursive=true) const {
226 if (!recursive || !owner_)
231 /// try to get a inset pointer from it's id if we have
232 /// an inset to give back!
233 virtual InsetOld * getInsetFromID(int /*id*/) const { return 0; }
234 /// if this insets owns paragraphs (f.ex. InsetText) then it
235 /// should return it's very first one!
236 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
238 virtual LyXText * getText(int /*num*/) const { return 0; }
240 virtual bool haveParagraphs() const {
244 /// return the cursor if we own one otherwise giv'em just the
245 /// BufferView cursor to work with.
246 virtual LyXCursor const & cursor(BufferView * bview) const;
251 /// lock cell with given index
252 virtual void edit(BufferView *, int /*index*/) {}
254 /// used to toggle insets
255 // is the inset open?
256 virtual bool isOpen() const { return false; }
258 virtual void open(BufferView *) {}
260 virtual void close(BufferView *) const {}
261 /// check if the font of the char we want inserting is correct
262 /// and modify it if it is not.
263 virtual bool checkInsertChar(LyXFont &);
264 /// we need this here because collapsed insets are only EDITABLE
265 virtual void setFont(BufferView *, LyXFont const &,
266 bool toggleall = false, bool selectall = false);
268 // needed for spellchecking text
270 virtual bool allowSpellcheck() const { return false; }
272 // should this inset be handled like a normal charater
273 virtual bool isChar() const { return false; }
274 // is this equivalent to a letter?
275 virtual bool isLetter() const { return false; }
276 // is this equivalent to a space (which is BTW different from
277 // a line separator)?
278 virtual bool isSpace() const { return false; }
279 // should we have a non-filled line before this inset?
280 virtual bool display() const { return false; }
281 // should we break lines after this inset?
282 virtual bool isLineSeparator() const { return false; }
283 // if this inset has paragraphs should they be output all as default
284 // paragraphs with "Standard" layout?
285 virtual bool forceDefaultParagraphs(InsetOld const *) const;
286 /** returns true if, when outputing LaTeX, font changes should
287 be closed before generating this inset. This is needed for
288 insets that may contain several paragraphs */
289 virtual bool noFontChange() const { return false; }
291 virtual void getDrawFont(LyXFont &) const {}
292 /* needed for widths which are % of something
293 returns the value of \textwidth in this inset. Most of the
294 time this is the width of the workarea, but if there is a
295 minipage somewhere, it will be the width of this minipage */
296 virtual int latexTextWidth(BufferView *) const;
298 /// mark the inset contents as erased (for change tracking)
299 virtual void markErased() {}
301 /** Adds a LaTeX snippet to the Preview Loader for transformation
302 * into a bitmap image. Does not start the laoding process.
304 * Most insets have no interest in this capability, so the method
307 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
312 mutable int top_baseline;
315 /// Used to identify the inset for cursor positioning when undoing
318 static unsigned int inset_id;
320 mutable Dimension dim_;
324 UpdatableInset * owner_;
327 /** We store the LColor::color value as an int to get LColor.h out
328 * of the header file.
330 int background_color_;
334 /** \c InsetOld_code is a wrapper for InsetOld::Code.
335 * It can be forward-declared and passed as a function argument without
336 * having to expose inset.h.
338 class InsetOld_code {
341 InsetOld_code(InsetOld::Code val) : val_(val) {}
342 operator InsetOld::Code() const{ return val_; }
347 * returns true if pointer argument is valid
348 * and points to an editable inset
350 bool isEditableInset(InsetOld const * i);
354 * returns true if pointer argument is valid
355 * and points to a highly editable inset
357 bool isHighlyEditableInset(InsetOld const * i);