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