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