4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
35 namespace lyx { namespace graphics { class PreviewLoader; } }
39 /// Common base class to all insets
41 // Do not add _any_ (non-static) data members as this would inflate
42 // everything storing large quantities of insets. Mathed e.g. would
48 typedef ptrdiff_t difference_type;
49 /// short of anything else reasonable
50 typedef size_t size_type;
51 /// type for cell indices
52 typedef size_t idx_type;
53 /// type for cursor positions
54 typedef ptrdiff_t pos_type;
55 /// type for row numbers
56 typedef size_t row_type;
57 /// type for column numbers
58 typedef size_t col_type;
60 /// virtual base class destructor
61 virtual ~InsetBase() {}
62 /// replicate ourselves
63 virtual std::auto_ptr<InsetBase> clone() const = 0;
65 /// identification as math inset
66 virtual MathInset * asMathInset() { return 0; }
67 /// identification as non-math inset
68 virtual UpdatableInset * asUpdatableInset() { return 0; }
70 // the real dispatcher
71 DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
74 virtual void edit(LCursor & cur, bool left);
76 virtual void edit(LCursor & cur, int x, int y);
78 /// compute the size of the object returned in dim
79 virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
80 /// draw inset and update (xo, yo)-cache
81 virtual void draw(PainterInfo & pi, int x, int y) const = 0;
82 /// draw inset selection if necessary
83 virtual void drawSelection(PainterInfo &, int, int) const {}
85 virtual bool editing(BufferView * bv) const;
86 /// draw four angular markers
87 void drawMarkers(PainterInfo & pi, int x, int y) const;
88 /// draw two angular markers
89 void drawMarkers2(PainterInfo & pi, int x, int y) const;
90 /// add space for markers
91 void metricsMarkers(Dimension & dim, int framesize = 1) const;
92 /// add space for markers
93 void metricsMarkers2(Dimension & dim, int framesize = 1) const;
94 /// last drawn position for 'important' insets
95 virtual int xo() const { return 0; }
96 /// last drawn position for 'important' insets
97 virtual int yo() const { return 0; }
98 /// set x/y drawing position cache if available
99 virtual void setPosCache(PainterInfo const &, int, int) const {}
100 /// do we cover screen position x/y?
101 virtual bool covers(int x, int y) const;
102 /// get the screen positions of the cursor (see note in cursor.C)
103 virtual void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
105 /// is this an inset that can be moved into?
106 virtual bool isActive() const { return nargs() > 0; }
107 /// Where should we go when we press the up or down cursor key?
108 virtual bool idxUpDown(LCursor & cur, bool up) const;
109 /// Where should we go when we press the up or down cursor key?
110 virtual bool idxUpDown2(LCursor & cur, bool up) const;
111 /// Move one cell to the left
112 virtual bool idxLeft(LCursor &) const { return false; }
113 /// Move one cell to the right
114 virtual bool idxRight(LCursor &) const { return false; }
116 /// Move one physical cell up
117 virtual bool idxNext(LCursor &) const { return false; }
118 /// Move one physical cell down
119 virtual bool idxPrev(LCursor &) const { return false; }
121 /// Target pos when we enter the inset from the left by pressing "Right"
122 virtual bool idxFirst(LCursor &) const { return false; }
123 /// Target pos when we enter the inset from the right by pressing "Left"
124 virtual bool idxLast(LCursor &) const { return false; }
126 /// Where should we go if we press home?
127 virtual bool idxHome(LCursor &) const { return false; }
128 /// Where should we go if we press end?
129 virtual bool idxEnd(LCursor &) const { return false; }
131 /// Delete a cell and move cursor
132 virtual bool idxDelete(idx_type &) { return false; }
133 /// pulls cell after pressing erase
134 virtual void idxGlue(idx_type) {}
135 // returns list of cell indices that are "between" from and to for
136 // selection purposes
137 virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
139 /// to which column belongs a cell with a given index?
140 virtual col_type col(idx_type) const { return 0; }
141 /// to which row belongs a cell with a given index?
142 virtual row_type row(idx_type) const { return 0; }
143 /// cell idex corresponding to row and column;
144 virtual idx_type index(row_type row, col_type col) const;
145 /// any additional x-offset when drawing a cell?
146 virtual int cellXOffset(idx_type) const { return 0; }
147 /// any additional y-offset when drawing a cell?
148 virtual int cellYOffset(idx_type) const { return 0; }
149 /// can we enter this cell?
150 virtual bool validCell(idx_type) const { return true; }
151 /// number of embedded cells
152 virtual size_t nargs() const { return 0; }
153 /// number of rows in gridlike structures
154 virtual size_t nrows() const { return 0; }
155 /// number of columns in gridlike structures
156 virtual size_t ncols() const { return 0; }
157 /// is called when the cursor leaves this inset
158 virtual void notifyCursorLeaves(idx_type) {}
160 /// request "external features"
161 virtual void validate(LaTeXFeatures &) const {}
162 /// Appends \c list with all labels found within this inset.
163 virtual void getLabelList(Buffer const &,
164 std::vector<std::string> & /* list */) const {}
166 /// describe content if cursor inside
167 virtual void infoize(std::ostream &) const {}
168 /// describe content if cursor behind
169 virtual void infoize2(std::ostream &) const {}
171 /// plain ascii output
172 virtual int plaintext(Buffer const &, std::ostream & os,
173 OutputParams const &) const;
175 virtual int linuxdoc(Buffer const &, std::ostream & os,
176 OutputParams const &) const;
178 virtual int docbook(Buffer const &, std::ostream & os,
179 OutputParams const &) const;
190 /// what appears in the minibuffer when opening
191 virtual std::string const editMessage() const;
193 virtual EDITABLE editable() const;
194 /// can we go further down on mouse click?
195 virtual bool descendable() const { return false; }
197 virtual bool isTextInset() const { return false; }
198 /// return true if the inset should be removed automatically
199 virtual bool autoDelete() const;
201 /** This is not quite the correct place for this enum. I think
202 the correct would be to let each subclass of Inset declare
203 its own enum code. Actually the notion of an InsetOld::Code
204 should be avoided, but I am not sure how this could be done
210 TOC_CODE, // do these insets really need a code? (ale)
270 MATHMACRO_CODE, // 30
302 /// returns true the inset can hold an inset of given type
303 virtual bool insetAllowed(Code) const { return false; }
304 // if this inset has paragraphs should they be output all as default
305 // paragraphs with "Standard" layout?
306 virtual bool forceDefaultParagraphs(InsetBase const *) const { return false; }
308 virtual std::string const & getInsetName() const;
309 /// used to toggle insets
310 // is the inset open?
311 virtual bool isOpen() const { return false; }
313 virtual void open() {}
315 virtual void close() {}
316 // should this inset be handled like a normal charater
317 virtual bool isChar() const { return false; }
318 // is this equivalent to a letter?
319 virtual bool isLetter() const { return false; }
320 // is this equivalent to a space (which is BTW different from
321 // a line separator)?
322 virtual bool isSpace() const { return false; }
323 // should we have a non-filled line before this inset?
324 virtual bool display() const { return false; }
325 // should we break lines after this inset?
326 virtual bool isLineSeparator() const { return false; }
327 /// dumps content to lyxerr
328 virtual void dump() const;
330 virtual void write(Buffer const &, std::ostream &) const {}
332 virtual void read(Buffer const &, LyXLex &) {}
333 /// returns the number of rows (\n's) of generated tex code.
334 virtual int latex(Buffer const &, std::ostream &,
335 OutputParams const &) const { return 0; }
336 /// returns true to override begin and end inset in file
337 virtual bool directWrite() const;
339 virtual bool allowSpellCheck() const { return false; }
341 /// if this insets owns text cells (e.g. InsetText) return cell num
342 virtual LyXText * getText(int /*num*/) const { return 0; }
344 virtual int numParagraphs() const { return 0; }
345 /// returns cell covering position (x,y), -1 if none exists
346 virtual int getCell(int x, int y) const;
348 /** Adds a LaTeX snippet to the Preview Loader for transformation
349 * into a bitmap image. Does not start the laoding process.
351 * Most insets have no interest in this capability, so the method
354 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
356 // the real dispatcher
358 DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
360 /// returns LyX code associated with the inset. Used for TOC, ...)
361 virtual Code lyxCode() const { return NO_CODE; }
363 /// -1: text mode, 1: math mode, 0 undecided
364 enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
365 /// return text or mathmode if that is possible to determine
366 virtual mode_type currentMode() const { return UNDECIDED_MODE; }
368 /// FIXME: This ought to die.
369 virtual void setOwner(UpdatableInset *) {}
371 virtual UpdatableInset * owner() const { return 0; }
373 /// is this inset allowed within a font change?
374 virtual bool noFontChange() const { return false; }
377 virtual void markErased();
379 virtual int width() const { return 10; }
381 virtual int ascent() const { return 10; }
383 virtual int descent() const { return 10; }
388 * returns true if pointer argument is valid
389 * and points to an editable inset
391 bool isEditableInset(InsetBase const * inset);
395 * returns true if pointer argument is valid
396 * and points to a highly editable inset
398 bool isHighlyEditableInset(InsetBase const * inset);