]> git.lyx.org Git - features.git/blob - src/insets/Inset.h
Rename XHTMLStream to XMLStream, move it to another file, and prepare for DocBook...
[features.git] / src / insets / Inset.h
1 // -*- C++ -*-
2 /**
3  * \file Inset.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author Jürgen Vigna
9  * \author Lars Gullik Bjønnes
10  * \author Matthias Ettrich
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef INSETBASE_H
16 #define INSETBASE_H
17
18 #include "ColorCode.h"
19 #include "InsetCode.h"
20 #include "InsetLayout.h"
21 #include "LayoutEnums.h"
22 #include "OutputEnums.h"
23 #include "OutputParams.h"
24
25 #include "support/strfwd.h"
26 #include "support/types.h"
27 #include "support/FileNameList.h"
28
29 #include <climits>
30
31
32 namespace lyx {
33
34 class BiblioInfo;
35 class Buffer;
36 class BufferView;
37 class Change;
38 class CompletionList;
39 class Cursor;
40 class CursorSlice;
41 class Dimension;
42 class DocIterator;
43 class Encoding;
44 class FuncRequest;
45 class FuncStatus;
46 class InsetArgument;
47 class InsetCollapsible;
48 class InsetCommand;
49 class InsetGraphics;
50 class InsetIterator;
51 class InsetLayout;
52 class InsetList;
53 class InsetMath;
54 class InsetTabular;
55 class InsetText;
56 class LaTeXFeatures;
57 class Lexer;
58 class MathAtom;
59 class MetricsInfo;
60 class OutputParams;
61 class PainterInfo;
62 class ParConstIterator;
63 class ParIterator;
64 class Text;
65 class TocBackend;
66 class TocList;
67 class XMLStream;
68 class otexstream;
69
70 namespace graphics { class PreviewLoader; }
71
72
73 /// returns the InsetCode corresponding to the \c name.
74 /// Eg, insetCode("branch") == BRANCH_CODE
75 InsetCode insetCode(std::string const & name);
76 /// returns the Inset name corresponding to the \c InsetCode.
77 /// Eg, insetName(BRANCH_CODE) == "branch"
78 std::string insetName(InsetCode);
79 /// returns the Inset name corresponding to the \c InsetCode.
80 /// Eg, insetDisplayName(BRANCH_CODE) == _("Branch")
81 docstring insetDisplayName(InsetCode);
82 ///
83 static int const TOC_ENTRY_LENGTH = 120;
84
85 /// Common base class to all insets
86
87 // Do not add _any_ (non-static) data members as this would inflate
88 // everything storing large quantities of insets. Mathed e.g. would
89 // suffer.
90
91 class Inset {
92 public:
93         ///
94         enum EntryDirection {
95                 ENTRY_DIRECTION_IGNORE,
96                 ENTRY_DIRECTION_RIGHT,
97                 ENTRY_DIRECTION_LEFT
98         };
99         ///
100         typedef ptrdiff_t  difference_type;
101         /// short of anything else reasonable
102         typedef size_t     size_type;
103         /// type for cell indices
104         typedef size_t     idx_type;
105         /// type for cursor positions
106         typedef ptrdiff_t  pos_type;
107         /// type for row numbers
108         typedef size_t     row_type;
109         /// type for column numbers
110         typedef size_t     col_type;
111
112         /// virtual base class destructor
113         virtual ~Inset() {}
114
115         /// change associated Buffer
116         virtual void setBuffer(Buffer & buffer);
117         /// reset associated Buffer to null value
118         virtual void resetBuffer();
119         /// retrieve associated Buffer
120         Buffer & buffer();
121         Buffer const & buffer() const;
122         /// Returns true if buffer_ actually points to a Buffer that has
123         /// been loaded into LyX and is still open. Note that this will
124         /// always return false for cloned Buffers. If you want to allow
125         /// for the case of cloned Buffers, use isBufferValid().
126         bool isBufferLoaded() const;
127         /// Returns true if this is a loaded buffer or a cloned buffer.
128         bool isBufferValid() const;
129
130         /// initialize view for this inset.
131         /**
132           * This is typically used after this inset is created interactively.
133           * Intented purpose is to sanitize internal state with regard to current
134           * Buffer.
135           **/
136         virtual void initView() {}
137         /// \return true if this inset is labeled.
138         virtual bool isLabeled() const { return false; }
139
140         /// identification as math inset
141         virtual InsetMath * asInsetMath() { return 0; }
142         /// identification as math inset
143         virtual InsetMath const * asInsetMath() const { return 0; }
144         /// true for 'math' math inset, but not for e.g. mbox
145         virtual bool inMathed() const { return false; }
146         /// is this inset based on the InsetText class?
147         virtual InsetText * asInsetText() { return 0; }
148         /// is this inset based on the InsetText class?
149         virtual InsetText const * asInsetText() const { return 0; }
150         /// is this inset based on the InsetCollapsible class?
151         virtual InsetCollapsible * asInsetCollapsible() { return 0; }
152         /// is this inset based on the InsetCollapsible class?
153         virtual InsetCollapsible const * asInsetCollapsible() const { return 0; }
154         /// is this inset based on the InsetTabular class?
155         virtual InsetTabular * asInsetTabular() { return 0; }
156         /// is this inset based on the InsetTabular class?
157         virtual InsetTabular const * asInsetTabular() const { return 0; }
158         /// is this inset based on the InsetCommand class?
159         virtual InsetCommand * asInsetCommand() { return 0; }
160         /// is this inset based on the InsetCommand class?
161         virtual InsetCommand const * asInsetCommand() const { return 0; }
162         /// is this inset based on the InsetArgument class?
163         virtual InsetArgument const * asInsetArgument() const { return nullptr; }
164         /// is this inset based on the InsetGraphics class?
165         virtual InsetGraphics * asInsetGraphics() { return 0; }
166         /// is this inset based on the InsetGraphics class?
167         virtual InsetGraphics const * asInsetGraphics() const { return 0; }
168
169         /// the real dispatcher
170         void dispatch(Cursor & cur, FuncRequest & cmd);
171         /**
172          * \returns true if this function made a definitive decision on
173          * whether the inset wants to handle the request \p cmd or not.
174          * The result of this decision is put into \p status.
175          *
176          * Every request that is enabled in this method needs to be handled
177          * in doDispatch(). Normally we have a 1:1 relationship between the
178          * requests handled in getStatus() and doDispatch(), but there are
179          * some exceptions:
180          * - A request that is disabled in getStatus() does not need to
181          *   appear in doDispatch(). It is guaranteed that doDispatch()
182          *   is never called with this request.
183          * - A few requests are en- or disabled in Inset::getStatus().
184          *   These need to be handled in the doDispatch() methods of the
185          *   derived insets, since Inset::doDispatch() has not enough
186          *   information to handle them.
187          * - LFUN_MOUSE_* need not to be handled in getStatus(), because these
188          *   are dispatched directly
189          */
190         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd,
191                 FuncStatus & status) const;
192
193         /// cursor enters
194         virtual void edit(Cursor & cur, bool front,
195                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
196         /// sets cursor recursively descending into nested editable insets
197         /**
198         \return the inset pointer if x,y is covering that inset
199         \param x,y are absolute screen coordinates.
200         */
201         /// Note: this method must preserve the selection status. See:
202         /// https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg199001.html
203         virtual Inset * editXY(Cursor & cur, int x, int y);
204
205         /// The default margin inside text insets
206         static int textOffset(BufferView const *) { return 4; }
207         ///
208         virtual int topOffset(BufferView const *bv) const { return textOffset(bv); }
209         ///
210         virtual int bottomOffset(BufferView const *bv) const { return textOffset(bv); }
211         ///
212         virtual int leftOffset(BufferView const *bv) const { return textOffset(bv); }
213         ///
214         virtual int rightOffset(BufferView const *bv) const { return textOffset(bv); }
215
216         /// compute the size of the object returned in dim
217         virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
218         /// draw inset and update (xo, yo)-cache
219         virtual void draw(PainterInfo & pi, int x, int y) const = 0;
220         /// draw inset selection if necessary
221         virtual void drawSelection(PainterInfo &, int, int) const {}
222         /// draw inset background if the inset has an own background and a
223         /// selection is drawn by drawSelection.
224         virtual void drawBackground(PainterInfo &, int, int) const;
225         ///
226         virtual bool editing(BufferView const * bv) const;
227         ///
228         virtual bool showInsetDialog(BufferView *) const;
229
230         /// draw two angular markers
231         virtual void drawMarkers(PainterInfo & pi, int x, int y) const;
232         /// add space for markers
233         void metricsMarkers(Dimension & dim, int framesize = 1) const;
234         /// add space for markers
235         void metricsMarkers2(Dimension & dim, int framesize = 1) const;
236         /// draw inset decoration if necessary.
237         /// This can use \c drawMarkers() for example.
238         virtual void drawDecoration(PainterInfo &, int, int) const {}
239
240         /// last metrics computed for the inset
241         Dimension const dimension(BufferView const &) const;
242         /// last drawn position for 'important' insets
243         int xo(BufferView const & bv) const;
244         /// last drawn position for 'important' insets
245         int yo(BufferView const & bv) const;
246         /// do we cover screen position x/y?
247         bool covers(BufferView const & bv, int x, int y) const;
248         /// get the screen positions of the cursor (see note in Cursor.cpp)
249         virtual void cursorPos(BufferView const & bv,
250                 CursorSlice const & sl, bool boundary, int & x, int & y) const;
251
252         /// Allow multiple blanks
253         virtual bool isFreeSpacing() const;
254         /// Don't eliminate empty paragraphs
255         virtual bool allowEmpty() const;
256         /// Force inset into LTR environment if surroundings are RTL
257         virtual bool forceLTR(OutputParams const &) const;
258         /// whether to include this inset in the strings generated for the TOC
259         virtual bool isInToc() const;
260
261         /// Where should we go when we press the up or down cursor key?
262         virtual bool idxUpDown(Cursor & cur, bool up) const;
263         /// Move one cell backwards
264         virtual bool idxBackward(Cursor &) const { return false; }
265         /// Move one cell forward
266         virtual bool idxForward(Cursor &) const { return false; }
267
268         /// Move to the next cell
269         virtual bool idxNext(Cursor &) const { return false; }
270         /// Move to the previous cell
271         virtual bool idxPrev(Cursor &) const { return false; }
272
273         /// Target pos when we enter the inset while moving forward
274         virtual bool idxFirst(Cursor &) const { return false; }
275         /// Target pos when we enter the inset while moving backwards
276         virtual bool idxLast(Cursor &) const { return false; }
277
278         /// Delete a cell and move cursor
279         virtual bool idxDelete(idx_type &) { return false; }
280         /// pulls cell after pressing erase
281         virtual void idxGlue(idx_type) {}
282         /// returns list of cell indices that are "between" from and to for
283         /// selection purposes
284         virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
285
286         /// to which column belongs a cell with a given index?
287         virtual col_type col(idx_type) const { return 0; }
288         /// to which row belongs a cell with a given index?
289         virtual row_type row(idx_type) const { return 0; }
290         /// cell index corresponding to row and column;
291         virtual idx_type index(row_type row, col_type col) const;
292         /// number of embedded cells
293         virtual size_t nargs() const { return 0; }
294         /// number of rows in gridlike structures
295         virtual size_t nrows() const { return 0; }
296         /// number of columns in gridlike structures
297         virtual size_t ncols() const { return 0; }
298         /// Is called when the cursor leaves this inset.
299         /// Returns true if cursor is now invalid, e.g. if former
300         /// insets in higher cursor slices of \c old do not exist
301         /// anymore.
302         /// \c old is the old cursor, the last slice points to this.
303         /// \c cur is the new cursor. Use the update flags to cause a redraw.
304         virtual bool notifyCursorLeaves(Cursor const & /*old*/, Cursor & /*cur*/)
305                 { return false; }
306         /// Is called when the cursor enters this inset.
307         /// Returns true if cursor is now invalid, e.g. if former
308         /// insets in higher cursor slices of \c old do not exist
309         /// anymore.
310         /// \c cur is the new cursor, some slice points to this. Use the update
311         /// flags to cause a redraw.
312         virtual bool notifyCursorEnters(Cursor & /*cur*/)
313                 { return false; }
314         /// is called when the mouse enters or leaves this inset
315         /// return true if this inset needs a repaint
316         virtual bool setMouseHover(BufferView const *, bool) const
317                 { return false; }
318         /// return true if this inset is hovered (under mouse)
319         /// This is by now only used by mathed to draw corners
320         /// (Inset::drawMarkers() and Inset::drawMarkers2()).
321         /// Other insets do not have to redefine this function to
322         /// return the correct status of mouseHovered.
323         virtual bool mouseHovered(BufferView const *) const { return false; }
324
325         /// request "external features"
326         virtual void validate(LaTeXFeatures &) const {}
327
328         /// Validate LFUN_INSET_MODIFY argument.
329         virtual bool validateModifyArgument(docstring const &) const { return true; }
330
331         /// describe content if cursor inside
332         virtual void infoize(odocstream &) const {}
333         /// describe content if cursor behind
334         virtual void infoize2(odocstream &) const {}
335
336         enum { PLAINTEXT_NEWLINE = 10000 };
337
338         /// plain text output in ucs4 encoding
339         /// return the number of characters; in case of multiple lines of
340         /// output, add PLAINTEXT_NEWLINE to the number of chars in the last line
341         virtual int plaintext(odocstringstream &, OutputParams const &,
342                               size_t max_length = INT_MAX) const = 0;
343         /// docbook output
344         virtual int docbook(odocstream & os, OutputParams const &) const;
345         /// XHTML output
346         /// the inset is expected to write XHTML to the XMLStream
347         /// \return any "deferred" material that should be written outside the
348         /// normal stream, and which will in fact be written after the current
349         /// paragraph closes. this is appropriate e.g. for floats.
350         virtual docstring xhtml(XMLStream &, OutputParams const &) const;
351
352         /// Writes a string representation of the inset to the odocstream.
353         /// This one should be called when you want the whole contents of
354         /// the inset.
355         virtual void toString(odocstream &) const {}
356         /// Appends a potentially abbreviated version of the inset to
357         /// \param str. Intended for use by the TOC.
358         virtual void forOutliner(docstring & str,
359                                                          size_t const maxlen = TOC_ENTRY_LENGTH,
360                                                          bool const shorten = true) const;
361
362         /// Can a cursor be put in there ?
363         /// Forced to false for insets that have hidden contents, like
364         /// InsetMathCommand and InsetInfo.
365         virtual bool isActive() const { return nargs() > 0; }
366         /// can the contents of the inset be edited on screen ?
367         // equivalent to isActive except for closed InsetCollapsible
368         virtual bool editable() const;
369         /// has the Inset settings that can be modified in a dialog ?
370         virtual bool hasSettings() const;
371         /// can we go further down on mouse click?
372         /// true for InsetCaption, InsetCollapsibles (not ButtonOnly), InsetTabular
373         virtual bool descendable(BufferView const &) const { return false; }
374         /// can we click at the specified position ?
375         virtual bool clickable(BufferView const &, int, int) const { return false; }
376         /// Move one cell backwards
377         virtual bool allowsCaptionVariation(std::string const &) const { return false; }
378         // true for insets that have a table structure (InsetMathGrid, InsetTabular)
379         virtual bool isTable() const { return false; }
380
381         /// does this contain text that can be change track marked in DVI?
382         virtual bool canTrackChanges() const { return false; }
383         /// Will this inset paint its own change tracking status (in the parent
384         /// paragraph) or will it let RowPainter handle it?
385         virtual bool canPaintChange(BufferView const &) const { return false; }
386         /// return true if the inset should be removed automatically
387         virtual bool autoDelete() const;
388
389         /// Returns true if the inset supports completions.
390         virtual bool completionSupported(Cursor const &) const { return false; }
391         /// Returns true if the inset supports inline completions at the
392         /// cursor position. In this case the completion might be stored
393         /// in the BufferView's inlineCompletion property.
394         virtual bool inlineCompletionSupported(Cursor const & /*cur*/) const
395                 { return false; }
396         /// Return true if the inline completion should be automatic.
397         virtual bool automaticInlineCompletion() const { return true; }
398         /// Return true if the popup completion should be automatic.
399         virtual bool automaticPopupCompletion() const { return true; }
400         /// Return true if the cursor should indicate a completion.
401         virtual bool showCompletionCursor() const { return true; }
402         /// Returns completion suggestions at cursor position. Return an
403         /// null pointer if no completion is a available or possible.
404         /// The caller is responsible to free the returned object!
405         virtual CompletionList const * createCompletionList(Cursor const &) const
406                 { return 0; }
407         /// Returns the completion prefix to filter the suggestions for completion.
408         /// This is only called if completionList returned a non-null list.
409         virtual docstring completionPrefix(Cursor const &) const;
410         /// Do a completion at the cursor position. Return true on success.
411         /// The completion does not contain the prefix. If finished is true, the
412         /// completion is final. If finished is false, completion might only be
413         /// a partial completion.
414         virtual bool insertCompletion(Cursor & /*cur*/,
415                 docstring const & /*completion*/, bool /*finished*/)
416                 { return false; }
417         /// Get the completion inset position and size
418         virtual void completionPosAndDim(Cursor const &, int & /*x*/, int & /*y*/,
419                 Dimension & /*dim*/) const {}
420
421         /// returns true if the inset can hold an inset of given type
422         virtual bool insetAllowed(InsetCode) const { return false; }
423         /// should this inset use the empty layout by default rather than
424         /// the standard layout? (default: only if that is forced.)
425         virtual bool usePlainLayout() const { return forcePlainLayout(); }
426         /// if this inset has paragraphs should they be forced to use the
427         /// empty layout?
428         virtual bool forcePlainLayout(idx_type = 0) const { return false; }
429         /// if this inset has paragraphs should the user be allowed to
430         /// customize alignment, etc?
431         virtual bool allowParagraphCustomization(idx_type = 0) const
432                 { return true; }
433         /// Is the width forced to some value?
434         virtual bool hasFixedWidth() const { return false; }
435         /// if this inset has paragraphs should they be forced to use a
436         /// local font language switch?
437         virtual bool forceLocalFontSwitch() const { return false; }
438         /// if this inset has paragraphs should they be forced to use a
439         /// font language switch that switches paragraph directions
440         /// (relevant with polyglossia only)?
441         virtual bool forceParDirectionSwitch() const { return false; }
442         /// Does the inset force a specific encoding?
443         virtual Encoding const * forcedEncoding(Encoding const *, Encoding const *) const
444         { return 0; }
445
446
447         /// Is the content of this inset part of the output document?
448         virtual bool producesOutput() const { return true; }
449         /// Is the content of this inset part of the immediate (visible) text sequence?
450         virtual bool isPartOfTextSequence() const { return producesOutput(); }
451
452         /// \return Tool tip for this inset.
453         /// This default implementation returns an empty string. This can be
454         /// either plain text or Qt html, and formatToolTip will be called
455         /// on it before display in both cases.
456         virtual docstring toolTip(BufferView const & bv, int x, int y) const;
457
458         /// \return Context menu identifier. This function determines
459         /// whose Inset's menu should be shown for the given position.
460         virtual std::string contextMenu(BufferView const & bv, int x, int y) const;
461
462         /// \return Context menu identifier for this inset.
463         /// This default implementation returns an empty string.
464         virtual std::string contextMenuName() const;
465
466
467         virtual docstring layoutName() const;
468         ///
469         virtual InsetLayout const & getLayout() const;
470         ///
471         virtual bool isPassThru() const { return getLayout().isPassThru(); }
472         /// Is this inset's layout defined in the document's textclass?
473         bool undefined() const;
474         /// should this inset be handled like a normal character?
475         /// (a character can be a letter or punctuation)
476         virtual bool isChar() const { return false; }
477         /// is this equivalent to a letter?
478         /// (a letter is a character that is considered part of a word)
479         virtual bool isLetter() const { return false; }
480         /// is this equivalent to a space (which is BTW different from
481         /// a line separator)?
482         virtual bool isSpace() const { return false; }
483         /// does this inset try to use all available space (like \\hfill does)?
484         virtual bool isHfill() const { return false; }
485
486         virtual OutputParams::CtObject CtObject(OutputParams const &) const { return OutputParams::CT_NORMAL; }
487
488         enum DisplayType {
489                 Inline = 0,
490                 AlignLeft,
491                 AlignCenter,
492                 AlignRight
493         };
494
495         /// should we have a non-filled line before this inset?
496         virtual DisplayType display() const { return Inline; }
497         /// indentation before this inset (only needed for displayed hull insets with fleqn option)
498         virtual int indent(BufferView const &) const { return 0; }
499         ///
500         virtual LyXAlignment contentAlignment() const { return LYX_ALIGN_NONE; }
501         /// should we break lines after this inset?
502         virtual bool isLineSeparator() const { return false; }
503         /// should paragraph indendation be omitted in any case?
504         virtual bool neverIndent() const { return false; }
505         /// dumps content to lyxerr
506         virtual void dump() const;
507         /// write inset in .lyx format
508         virtual void write(std::ostream &) const {}
509         /// read inset in .lyx format
510         virtual void read(Lexer &) {}
511         /** Export the inset to LaTeX.
512          *  Don't use a temporary stringstream if the final output is
513          *  supposed to go to a file.
514          *  \sa Buffer::writeLaTeXSource for the reason.
515          */
516         virtual void latex(otexstream &, OutputParams const &) const {}
517         /// returns true to override begin and end inset in file
518         virtual bool directWrite() const;
519         ///
520         virtual bool allowSpellCheck() const { return false; }
521
522         /// if this insets owns text cells (e.g. InsetText) return cell num
523         virtual Text * getText(int /*num*/) const { return 0; }
524
525         /** Adds a LaTeX snippet to the Preview Loader for transformation
526          *  into a bitmap image. Does not start the laoding process.
527          *
528          *  Most insets have no interest in this capability, so the method
529          *  defaults to empty.
530          */
531         virtual void addPreview(DocIterator const &,
532                 graphics::PreviewLoader &) const {}
533
534         /** Classifies the unicode characters appearing in a math inset
535          *  depending on whether they are to be translated as latex
536          *  math/text commands or used as math symbols without translation.
537          *
538          *  Only math insets have interest in this classification, so the
539          *  method defaults to empty.
540          */
541         virtual void initUnicodeMath() const {}
542
543         /// Add an entry to the TocList
544         /// Pass a DocIterator that points at the paragraph containing
545         /// the inset
546         ///
547         /// \param output_active : is the inset active or is it in an inactive
548         /// branch or a note?
549         ///
550         /// \param utype : is the toc being generated for use by the output
551         /// routines?
552         ///
553         /// \param tocbackend : where to add the toc information.
554         virtual void addToToc(DocIterator const & /* di */,
555                                                   bool /* output_active */,
556                               UpdateType /* utype*/,
557                               TocBackend & /* tocbackend */) const {}
558         /// Collect BibTeX information
559         virtual void collectBibKeys(InsetIterator const &, support::FileNameList &) const {}
560         /// Update the counters of this inset and of its contents.
561         /// The boolean indicates whether we are preparing for output, e.g.,
562         /// of XHTML.
563         virtual void updateBuffer(ParIterator const &, UpdateType, bool const) {}
564
565         /// Updates the inset's dialog
566         virtual Buffer const * updateFrontend() const;
567
568 public:
569         /// returns LyX code associated with the inset. Used for TOC, ...)
570         virtual InsetCode lyxCode() const { return NO_CODE; }
571
572         ///
573         enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
574         /// return text or mathmode if that is possible to determine
575         virtual mode_type currentMode() const { return UNDECIDED_MODE; }
576         /// returns whether changing mode during latex export is forbidden
577         virtual bool lockedMode() const { return false; }
578         /// returns whether only ascii chars are allowed during latex export
579         virtual bool asciiOnly() const { return false; }
580         /// returns whether this inset is allowed in other insets of given mode
581         virtual bool allowedIn(mode_type) const { return true; }
582         /**
583          * The font is inherited from the parent for LaTeX export if this
584          * method returns true. No open font changes are closed in front of
585          * the inset for LaTeX export, and the font is inherited for all other
586          * exports as well as on screen.
587          * If this method returns false all open font changes are closed in
588          * front of the inset for LaTeX export. The default font is used
589          * inside the inset for all exports and on screen.
590          */
591         virtual bool inheritFont() const { return true; }
592         /**
593          * If this method returns true all explicitly set font attributes
594          * are reset during editing operations.
595          * For copy/paste operations the language is never changed, since
596          * the language of a given text never changes if the text is
597          * formatted differently, while other font attribues like size may
598          * need to change if the text is copied from one environment to
599          * another one.
600          * If this method returns false no font attribute is reset.
601          * The default implementation returns true if the resetFont layout
602          * tag is set and otherwise the negation of inheritFont(),
603          * since inherited inset font attributes do not need to be changed,
604          * and non-inherited ones need to be set explicitly.
605          */
606         virtual bool resetFontEdit() const;
607
608         /// does the inset contain changes ?
609         virtual bool isChanged() const { return false; }
610         /// set the change for the entire inset
611         virtual void setChange(Change const &) {}
612         /// accept the changes within the inset
613         virtual void acceptChanges() {}
614         /// reject the changes within the inset
615         virtual void rejectChanges() {}
616
617         ///
618         virtual bool needsCProtection(bool const, bool const) const { return false; }
619
620         ///
621         virtual ColorCode backgroundColor(PainterInfo const &) const;
622         ///
623         virtual ColorCode labelColor() const;
624
625         /// Determine the action of backspace and delete: do we select instead of
626         /// deleting if not already selected?
627         virtual bool confirmDeletion() const { return false; }
628
629 protected:
630         /// Constructors
631         Inset(Buffer * buf) : buffer_(buf) {}
632         Inset(Inset const &) : buffer_(0) {}
633
634         /// replicate ourselves
635         friend class InsetList;
636         friend class MathAtom;
637         virtual Inset * clone() const = 0;
638
639         /** The real dispatcher.
640          *  Gets normally called from Cursor::dispatch(). Cursor::dispatch()
641          *  assumes the common case of 'LFUN handled, need update'.
642          *  This has to be overriden by calling Cursor::undispatched() or
643          *  Cursor::noScreenUpdate() if appropriate.
644          *  If you need to call the dispatch method of some inset directly
645          *  you may have to explicitly request an update at that place. Don't
646          *  do it in doDispatch(), since that causes nested updates when
647          *  called from Cursor::dispatch(), and these can lead to crashes.
648          *  \sa getStatus
649          */
650         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
651
652         Buffer * buffer_;
653 };
654
655 } // namespace lyx
656
657 #endif