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 &, std::ostream &,
188 LatexRunParams const &) const = 0;
190 virtual int linuxdoc(Buffer const &, std::ostream &,
191 LatexRunParams const &) const = 0;
193 virtual int docbook(Buffer const &, std::ostream &,
194 LatexRunParams const &) const = 0;
196 /// returns LyX code associated with the inset. Used for TOC, ...)
197 virtual InsetOld::Code lyxCode() const { return NO_CODE; }
199 /// returns true to override begin and end inset in file
200 virtual bool directWrite() const;
203 void setInsetName(std::string const & s) { name_ = s; }
205 std::string const & getInsetName() const { return name_; }
207 void setOwner(UpdatableInset * inset) { owner_ = inset; }
209 UpdatableInset * owner() const { return owner_; }
211 void setBackgroundColor(LColor_color);
213 LColor_color backgroundColor() const;
215 int x() const { return top_x; }
217 int y() const { return top_baseline; }
219 // because we could have fake text insets and have to call this
220 // inside them without cast!!!
222 virtual LyXText * getLyXText(BufferView const *,
223 bool recursive = false) const;
225 virtual void deleteLyXText(BufferView *, bool = true) const {}
226 /// returns the actuall scroll-value
227 virtual int scroll(bool recursive=true) const {
228 if (!recursive || !owner_)
233 /// if this insets owns paragraphs (f.ex. InsetText) then it
234 /// should return it's very first one!
235 virtual ParagraphList * getParagraphs(int /*num*/) const { return 0; }
237 virtual LyXText * getText(int /*num*/) const { return 0; }
239 virtual int numParagraphs() const { return 0; }
241 /// return the cursor if we own one otherwise giv'em just the
242 /// BufferView cursor to work with.
243 virtual LyXCursor const & cursor(BufferView * bview) const;
244 /// lock cell with given index
245 virtual void edit(BufferView *, int /*index*/) {}
247 /// used to toggle insets
248 // is the inset open?
249 virtual bool isOpen() const { return false; }
251 virtual void open(BufferView *) {}
253 virtual void close(BufferView *) const {}
254 /// check if the font of the char we want inserting is correct
255 /// and modify it if it is not.
256 virtual bool checkInsertChar(LyXFont &);
257 /// we need this here because collapsed insets are only EDITABLE
258 virtual void setFont(BufferView *, LyXFont const &,
259 bool toggleall = false, bool selectall = false);
261 // needed for spellchecking text
263 virtual bool allowSpellcheck() const { return false; }
265 // should this inset be handled like a normal charater
266 virtual bool isChar() const { return false; }
267 // is this equivalent to a letter?
268 virtual bool isLetter() const { return false; }
269 // is this equivalent to a space (which is BTW different from
270 // a line separator)?
271 virtual bool isSpace() const { return false; }
272 // should we have a non-filled line before this inset?
273 virtual bool display() const { return false; }
274 // should we break lines after this inset?
275 virtual bool isLineSeparator() const { return false; }
276 // if this inset has paragraphs should they be output all as default
277 // paragraphs with "Standard" layout?
278 virtual bool forceDefaultParagraphs(InsetOld const *) const;
279 /** returns true if, when outputing LaTeX, font changes should
280 be closed before generating this inset. This is needed for
281 insets that may contain several paragraphs */
282 virtual bool noFontChange() const { return false; }
284 virtual void getDrawFont(LyXFont &) const {}
285 /* needed for widths which are % of something
286 returns the value of \textwidth in this inset. Most of the
287 time this is the width of the workarea, but if there is a
288 minipage somewhere, it will be the width of this minipage */
289 virtual int latexTextWidth(BufferView *) const;
291 /// mark the inset contents as erased (for change tracking)
292 virtual void markErased() {}
294 /** Adds a LaTeX snippet to the Preview Loader for transformation
295 * into a bitmap image. Does not start the laoding process.
297 * Most insets have no interest in this capability, so the method
300 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
305 mutable int top_baseline;
308 /// Used to identify the inset for cursor positioning when undoing
311 mutable Dimension dim_;
315 UpdatableInset * owner_;
318 /** We store the LColor::color value as an int to get LColor.h out
319 * of the header file.
321 int background_color_;
325 /** \c InsetOld_code is a wrapper for InsetOld::Code.
326 * It can be forward-declared and passed as a function argument without
327 * having to expose inset.h.
329 class InsetOld_code {
332 InsetOld_code(InsetOld::Code val) : val_(val) {}
333 operator InsetOld::Code() const{ return val_; }
338 * returns true if pointer argument is valid
339 * and points to an editable inset
341 bool isEditableInset(InsetOld const * i);
345 * returns true if pointer argument is valid
346 * and points to a highly editable inset
348 bool isHighlyEditableInset(InsetOld const * i);