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;
83 virtual bool editing(BufferView * bv) const;
84 /// draw four angular markers
85 void drawMarkers(PainterInfo & pi, int x, int y) const;
86 /// draw two angular markers
87 void drawMarkers2(PainterInfo & pi, int x, int y) const;
88 /// add space for markers
89 void metricsMarkers(Dimension & dim, int framesize = 1) const;
90 /// add space for markers
91 void metricsMarkers2(Dimension & dim, int framesize = 1) const;
92 /// last drawn position for 'important' insets
93 virtual int xo() const { return 0; }
94 /// last drawn position for 'important' insets
95 virtual int yo() const { return 0; }
96 /// set x/y drawing position cache if available
97 virtual void setPosCache(PainterInfo const &, int, int) const {}
98 /// do we cover screen position x/y?
99 virtual bool covers(int x, int y) const;
100 /// get the screen positions of the cursor (see note in cursor.C)
101 virtual void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
103 /// is this an inset that can be moved into?
104 virtual bool isActive() const { return nargs() > 0; }
105 /// Where should we go when we press the up or down cursor key?
106 virtual bool idxUpDown(LCursor & cur, bool up) const;
107 /// Where should we go when we press the up or down cursor key?
108 virtual bool idxUpDown2(LCursor & cur, bool up) const;
109 /// Move one cell to the left
110 virtual bool idxLeft(LCursor &) const { return false; }
111 /// Move one cell to the right
112 virtual bool idxRight(LCursor &) const { return false; }
114 /// Move one physical cell up
115 virtual bool idxNext(LCursor &) const { return false; }
116 /// Move one physical cell down
117 virtual bool idxPrev(LCursor &) const { return false; }
119 /// Target pos when we enter the inset from the left by pressing "Right"
120 virtual bool idxFirst(LCursor &) const { return false; }
121 /// Target pos when we enter the inset from the right by pressing "Left"
122 virtual bool idxLast(LCursor &) const { return false; }
124 /// Where should we go if we press home?
125 virtual bool idxHome(LCursor &) const { return false; }
126 /// Where should we go if we press end?
127 virtual bool idxEnd(LCursor &) const { return false; }
129 /// Delete a cell and move cursor
130 virtual bool idxDelete(idx_type &) { return false; }
131 /// pulls cell after pressing erase
132 virtual void idxGlue(idx_type) {}
133 // returns list of cell indices that are "between" from and to for
134 // selection purposes
135 virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
137 /// to which column belongs a cell with a given index?
138 virtual col_type col(idx_type) const { return 0; }
139 /// to which row belongs a cell with a given index?
140 virtual row_type row(idx_type) const { return 0; }
141 /// cell idex corresponding to row and column;
142 virtual idx_type index(row_type row, col_type col) const;
143 /// any additional x-offset when drawing a cell?
144 virtual int cellXOffset(idx_type) const { return 0; }
145 /// any additional y-offset when drawing a cell?
146 virtual int cellYOffset(idx_type) const { return 0; }
147 /// can we enter this cell?
148 virtual bool validCell(idx_type) const { return true; }
149 /// number of embedded cells
150 virtual size_t nargs() const { return 0; }
151 /// number of rows in gridlike structures
152 virtual size_t nrows() const { return 0; }
153 /// number of columns in gridlike structures
154 virtual size_t ncols() const { return 0; }
155 /// is called when the cursor leaves this inset
156 virtual void notifyCursorLeaves(idx_type) {}
158 /// request "external features"
159 virtual void validate(LaTeXFeatures &) const {}
160 /// Appends \c list with all labels found within this inset.
161 virtual void getLabelList(Buffer const &,
162 std::vector<std::string> & /* list */) const {}
164 /// describe content if cursor inside
165 virtual void infoize(std::ostream &) const {}
166 /// describe content if cursor behind
167 virtual void infoize2(std::ostream &) const {}
169 /// plain ascii output
170 virtual int plaintext(Buffer const &, std::ostream & os,
171 OutputParams const &) const;
173 virtual int linuxdoc(Buffer const &, std::ostream & os,
174 OutputParams const &) const;
176 virtual int docbook(Buffer const &, std::ostream & os,
177 OutputParams const &) const;
188 /// what appears in the minibuffer when opening
189 virtual std::string const editMessage() const;
191 virtual EDITABLE editable() const;
192 /// can we go further down on mouse click?
193 virtual bool descendable() const { return false; }
195 virtual bool isTextInset() const { return false; }
196 /// return true if the inset should be removed automatically
197 virtual bool autoDelete() const;
199 /** This is not quite the correct place for this enum. I think
200 the correct would be to let each subclass of Inset declare
201 its own enum code. Actually the notion of an InsetOld::Code
202 should be avoided, but I am not sure how this could be done
208 TOC_CODE, // do these insets really need a code? (ale)
268 MATHMACRO_CODE, // 30
300 /// returns true the inset can hold an inset of given type
301 virtual bool insetAllowed(Code) const { return false; }
302 // if this inset has paragraphs should they be output all as default
303 // paragraphs with "Standard" layout?
304 virtual bool forceDefaultParagraphs(InsetBase const *) const { return false; }
306 virtual std::string const & getInsetName() const;
307 /// used to toggle insets
308 // is the inset open?
309 virtual bool isOpen() const { return false; }
311 virtual void open() {}
313 virtual void close() {}
314 // should this inset be handled like a normal charater
315 virtual bool isChar() const { return false; }
316 // is this equivalent to a letter?
317 virtual bool isLetter() const { return false; }
318 // is this equivalent to a space (which is BTW different from
319 // a line separator)?
320 virtual bool isSpace() const { return false; }
321 // should we have a non-filled line before this inset?
322 virtual bool display() const { return false; }
323 // should we break lines after this inset?
324 virtual bool isLineSeparator() const { return false; }
326 virtual void write(Buffer const &, std::ostream &) const {}
328 virtual void read(Buffer const &, LyXLex &) {}
329 /// returns the number of rows (\n's) of generated tex code.
330 virtual int latex(Buffer const &, std::ostream &,
331 OutputParams const &) const { return 0; }
332 /// returns true to override begin and end inset in file
333 virtual bool directWrite() const;
335 virtual bool allowSpellCheck() const { return false; }
337 /// if this insets owns text cells (e.g. InsetText) return cell num
338 virtual LyXText * getText(int /*num*/) const { return 0; }
340 virtual int numParagraphs() const { return 0; }
341 /// returns cell covering position (x,y), -1 if none exists
342 virtual int getCell(int x, int y) const;
344 /** Adds a LaTeX snippet to the Preview Loader for transformation
345 * into a bitmap image. Does not start the laoding process.
347 * Most insets have no interest in this capability, so the method
350 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
352 // the real dispatcher
354 DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
356 /// returns LyX code associated with the inset. Used for TOC, ...)
357 virtual Code lyxCode() const { return NO_CODE; }
359 /// -1: text mode, 1: math mode, 0 undecided
360 enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
361 /// return text or mathmode if that is possible to determine
362 virtual mode_type currentMode() const { return UNDECIDED_MODE; }
364 /// FIXME: This ought to die.
365 virtual void setOwner(UpdatableInset *) {}
367 virtual UpdatableInset * owner() const { return 0; }
369 /// is this inset allowed within a font change?
370 virtual bool noFontChange() const { return false; }
373 virtual void markErased();
375 virtual int width() const { return 10; }
377 virtual int ascent() const { return 10; }
379 virtual int descent() const { return 10; }
384 * returns true if pointer argument is valid
385 * and points to an editable inset
387 bool isEditableInset(InsetBase const * inset);
391 * returns true if pointer argument is valid
392 * and points to a highly editable inset
394 bool isHighlyEditableInset(InsetBase const * inset);