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"
42 class InsetOld : 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 InsetOld::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)
115 MATHMACRO_CODE, // 30
143 TEXT_TO_INSET_OFFSET = 2
159 InsetOld(InsetOld const & in);
166 /// what appears in the minibuffer when opening
167 virtual std::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(InsetOld::Code) const { return false; }
176 /// wrapper around the above
177 bool insetAllowed(InsetOld * 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 &, std::ostream &,
187 LatexRunParams const &) const = 0;
189 virtual int linuxdoc(Buffer const &, std::ostream &,
190 LatexRunParams const &) const = 0;
192 virtual int docbook(Buffer const &, std::ostream &,
193 LatexRunParams const &) 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(std::string const & s) { name_ = s; }
204 std::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 /// if this insets owns paragraphs (f.ex. InsetText) then it
233 /// should return it's very first one!
234 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
236 virtual LyXText * getText(int /*num*/) const { return 0; }
238 virtual int numParagraphs() const { return 0; }
240 /// return the cursor if we own one otherwise giv'em just the
241 /// BufferView cursor to work with.
242 virtual LyXCursor const & cursor(BufferView * bview) const;
243 /// lock cell with given index
244 virtual void edit(BufferView *, int /*index*/) {}
246 /// used to toggle insets
247 // is the inset open?
248 virtual bool isOpen() const { return false; }
250 virtual void open(BufferView *) {}
252 virtual void close(BufferView *) const {}
253 /// check if the font of the char we want inserting is correct
254 /// and modify it if it is not.
255 virtual bool checkInsertChar(LyXFont &);
256 /// we need this here because collapsed insets are only EDITABLE
257 virtual void setFont(BufferView *, LyXFont const &,
258 bool toggleall = false, bool selectall = false);
260 // should this inset be handled like a normal charater
261 virtual bool isChar() const { return false; }
262 // is this equivalent to a letter?
263 virtual bool isLetter() const { return false; }
264 // is this equivalent to a space (which is BTW different from
265 // a line separator)?
266 virtual bool isSpace() const { return false; }
267 // should we have a non-filled line before this inset?
268 virtual bool display() const { return false; }
269 // should we break lines after this inset?
270 virtual bool isLineSeparator() const { return false; }
271 // if this inset has paragraphs should they be output all as default
272 // paragraphs with "Standard" layout?
273 virtual bool forceDefaultParagraphs(InsetOld const *) const;
274 /** returns true if, when outputing LaTeX, font changes should
275 be closed before generating this inset. This is needed for
276 insets that may contain several paragraphs */
277 virtual bool noFontChange() const { return false; }
279 virtual void getDrawFont(LyXFont &) const {}
280 /* needed for widths which are % of something
281 returns the value of \textwidth in this inset. Most of the
282 time this is the width of the workarea, but if there is a
283 minipage somewhere, it will be the width of this minipage */
284 virtual int latexTextWidth(BufferView *) const;
286 /// mark the inset contents as erased (for change tracking)
287 virtual void markErased() {}
289 /** Adds a LaTeX snippet to the Preview Loader for transformation
290 * into a bitmap image. Does not start the laoding process.
292 * Most insets have no interest in this capability, so the method
295 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
300 mutable int top_baseline;
303 /// Used to identify the inset for cursor positioning when undoing
306 mutable Dimension dim_;
310 UpdatableInset * owner_;
313 /** We store the LColor::color value as an int to get LColor.h out
314 * of the header file.
316 int background_color_;
320 /** \c InsetOld_code is a wrapper for InsetOld::Code.
321 * It can be forward-declared and passed as a function argument without
322 * having to expose inset.h.
324 class InsetOld_code {
327 InsetOld_code(InsetOld::Code val) : val_(val) {}
328 operator InsetOld::Code() const{ return val_; }
333 * returns true if pointer argument is valid
334 * and points to an editable inset
336 bool isEditableInset(InsetOld const * i);
340 * returns true if pointer argument is valid
341 * and points to a highly editable inset
343 bool isHighlyEditableInset(InsetOld const * i);