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;
202 void setInsetName(string const & s) { name_ = s; }
204 string const & getInsetName() const { return name_; }
206 void setOwner(UpdatableInset * inset) { owner_ = inset; }
208 UpdatableInset * owner() const { return owner_; }
210 void setBackgroundColor(LColor::color);
212 LColor::color backgroundColor() const;
214 int x() const { return top_x; }
216 int y() const { return top_baseline; }
218 // because we could have fake text insets and have to call this
219 // inside them without cast!!!
221 virtual LyXText * getLyXText(BufferView const *,
222 bool recursive = false) const;
224 virtual void deleteLyXText(BufferView *, bool = true) const {}
225 /// returns the actuall scroll-value
226 virtual int scroll(bool recursive=true) const {
227 if (!recursive || !owner_)
232 /// try to get a inset pointer from it's id if we have
233 /// an inset to give back!
234 virtual InsetOld * getInsetFromID(int /*id*/) const { return 0; }
235 /// if this insets owns paragraphs (f.ex. InsetText) then it
236 /// should return it's very first one!
237 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
239 virtual bool haveParagraphs() const {
243 /// return the cursor if we own one otherwise giv'em just the
244 /// BufferView cursor to work with.
245 virtual LyXCursor const & cursor(BufferView * bview) const;
251 /// used to toggle insets
252 // is the inset open?
253 virtual bool isOpen() const { return false; }
255 virtual void open(BufferView *) {}
257 virtual void close(BufferView *) const {}
258 /// check if the font of the char we want inserting is correct
259 /// and modify it if it is not.
260 virtual bool checkInsertChar(LyXFont &);
261 /// we need this here because collapsed insets are only EDITABLE
262 virtual void setFont(BufferView *, LyXFont const &,
263 bool toggleall = false, bool selectall = false);
265 // needed for spellchecking text
267 virtual bool allowSpellcheck() const { return false; }
269 // should this inset be handled like a normal charater
270 virtual bool isChar() const { return false; }
271 // is this equivalent to a letter?
272 virtual bool isLetter() const { return false; }
273 // is this equivalent to a space (which is BTW different from
274 // a line separator)?
275 virtual bool isSpace() const { return false; }
276 // should we break lines after this inset?
277 virtual bool isLineSeparator() const { return false; }
278 // if this inset has paragraphs should they be output all as default
279 // paragraphs with "Standard" layout?
280 virtual bool forceDefaultParagraphs(InsetOld const *) const;
281 /** returns true if, when outputing LaTeX, font changes should
282 be closed before generating this inset. This is needed for
283 insets that may contain several paragraphs */
284 virtual bool noFontChange() const { return false; }
286 virtual void getDrawFont(LyXFont &) const {}
287 /* needed for widths which are % of something
288 returns the value of \textwidth in this inset. Most of the
289 time this is the width of the workarea, but if there is a
290 minipage somewhere, it will be the width of this minipage */
291 virtual int latexTextWidth(BufferView *) const;
293 /// mark the inset contents as erased (for change tracking)
294 virtual void markErased() {}
296 /** Adds a LaTeX snippet to the Preview Loader for transformation
297 * into a bitmap image. Does not start the laoding process.
299 * Most insets have no interest in this capability, so the method
302 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
304 /** Find the PreviewLoader, add a LaTeX snippet to it and
305 * start the loading process.
307 * Most insets have no interest in this capability, so the method
310 virtual void generatePreview() const {}
316 mutable int top_baseline;
319 /// Used to identify the inset for cursor positioning when undoing
322 static unsigned int inset_id;
324 mutable Dimension dim_;
328 UpdatableInset * owner_;
332 LColor::color background_color_;
337 * returns true if pointer argument is valid
338 * and points to an editable inset
340 bool isEditableInset(InsetOld const * i);
344 * returns true if pointer argument is valid
345 * and points to a highly editable inset
347 bool isHighlyEditableInset(InsetOld const * i);