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.
34 namespace lyx { namespace graphics { class PreviewLoader; } }
37 /// Common base class to all insets
39 // Do not add _any_ (non-static) data members as this would inflate
40 // everything storing large quantities of insets. Mathed e.g. would
46 typedef ptrdiff_t difference_type;
47 /// short of anything else reasonable
48 typedef size_t size_type;
49 /// type for cell indices
50 typedef size_t idx_type;
51 /// type for cursor positions
52 typedef ptrdiff_t pos_type;
53 /// type for row numbers
54 typedef size_t row_type;
55 /// type for column numbers
56 typedef size_t col_type;
58 /// virtual base class destructor
59 virtual ~InsetBase() {}
60 /// replicate ourselves
61 virtual std::auto_ptr<InsetBase> clone() const = 0;
63 /// identification as math inset
64 virtual MathInset * asMathInset() { return 0; }
65 /// identification as non-math inset
66 virtual UpdatableInset * asUpdatableInset() { return 0; }
68 // the real dispatcher
69 DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
72 virtual void edit(LCursor & cur, bool left);
74 virtual void edit(LCursor & cur, int x, int y);
76 /// compute the size of the object returned in dim
77 virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
78 /// draw inset and update (xo, yo)-cache
79 virtual void draw(PainterInfo & pi, int x, int y) const = 0;
80 /// last drawn position for 'important' insets
81 virtual int x() const { return 0; }
82 /// last drawn position for 'important' insets
83 virtual int y() const { return 0; }
85 /// is this an inset that can be moved into?
86 virtual bool isActive() const { return nargs() > 0; }
87 /// Where should we go when we press the up or down cursor key?
88 virtual bool idxUpDown(LCursor & cur, bool up) const;
89 /// Where should we go when we press the up or down cursor key?
90 virtual bool idxUpDown2(LCursor & cur, bool up) const;
91 /// Move one cell to the left
92 virtual bool idxLeft(LCursor &) const { return false; }
93 /// Move one cell to the right
94 virtual bool idxRight(LCursor &) const { return false; }
96 /// Move one physical cell up
97 virtual bool idxNext(LCursor &) const { return false; }
98 /// Move one physical cell down
99 virtual bool idxPrev(LCursor &) const { return false; }
101 /// Target pos when we enter the inset from the left by pressing "Right"
102 virtual bool idxFirst(LCursor &) const { return false; }
103 /// Target pos when we enter the inset from the right by pressing "Left"
104 virtual bool idxLast(LCursor &) const { return false; }
106 /// Where should we go if we press home?
107 virtual bool idxHome(LCursor &) const { return false; }
108 /// Where should we go if we press end?
109 virtual bool idxEnd(LCursor &) const { return false; }
111 /// Delete a cell and move cursor
112 virtual bool idxDelete(idx_type &) { return false; }
113 /// pulls cell after pressing erase
114 virtual void idxGlue(idx_type) {}
115 // returns list of cell indices that are "between" from and to for
116 // selection purposes
117 virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
119 /// to which column belongs a cell with a given index?
120 virtual col_type col(idx_type) const { return 0; }
121 /// to which row belongs a cell with a given index?
122 virtual row_type row(idx_type) const { return 0; }
123 /// cell idex corresponding to row and column;
124 virtual idx_type index(row_type row, col_type col) const;
125 /// any additional x-offset when drawing a cell?
126 virtual int cellXOffset(idx_type) const { return 0; }
127 /// any additional y-offset when drawing a cell?
128 virtual int cellYOffset(idx_type) const { return 0; }
129 /// can we enter this cell?
130 virtual bool validCell(idx_type) const { return true; }
132 virtual void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const;
133 /// number of embedded cells
134 virtual size_t nargs() const { return 0; }
135 /// number of rows in gridlike structures
136 virtual size_t nrows() const { return 0; }
137 /// number of columns in gridlike structures
138 virtual size_t ncols() const { return 0; }
139 /// is called when the cursor leaves this inset
140 virtual void notifyCursorLeaves(idx_type) {}
142 /// request "external features"
143 virtual void validate(LaTeXFeatures &) const {}
144 /// Appends \c list with all labels found within this inset.
145 virtual void getLabelList(Buffer const &,
146 std::vector<std::string> & /* list */) const {}
148 /// describe content if cursor inside
149 virtual void infoize(std::ostream &) const {}
150 /// describe content if cursor behind
151 virtual void infoize2(std::ostream &) const {}
153 /// plain ascii output
154 virtual int plaintext(Buffer const &, std::ostream & os,
155 OutputParams const &) const;
157 virtual int linuxdoc(Buffer const &, std::ostream & os,
158 OutputParams const &) const;
160 virtual int docbook(Buffer const &, std::ostream & os,
161 OutputParams const &) const;
172 /// what appears in the minibuffer when opening
173 virtual std::string const editMessage() const;
175 virtual EDITABLE editable() const;
176 /// can we go further down on mouse click?
177 virtual bool descendable() const { return false; }
179 virtual bool isTextInset() const { return false; }
180 /// return true if the inset should be removed automatically
181 virtual bool autoDelete() const;
183 /** This is not quite the correct place for this enum. I think
184 the correct would be to let each subclass of Inset declare
185 its own enum code. Actually the notion of an InsetOld::Code
186 should be avoided, but I am not sure how this could be done
192 TOC_CODE, // do these insets really need a code? (ale)
252 MATHMACRO_CODE, // 30
284 /// returns true the inset can hold an inset of given type
285 virtual bool insetAllowed(Code) const { return false; }
286 /// wrapper around the above
287 bool insetAllowed(InsetBase * inset) const;
288 // if this inset has paragraphs should they be output all as default
289 // paragraphs with "Standard" layout?
290 virtual bool forceDefaultParagraphs(InsetBase const *) const { return false; }
292 virtual std::string const & getInsetName() const;
293 /// used to toggle insets
294 // is the inset open?
295 virtual bool isOpen() const { return false; }
297 virtual void open() {}
299 virtual void close() {}
300 // should this inset be handled like a normal charater
301 virtual bool isChar() const { return false; }
302 // is this equivalent to a letter?
303 virtual bool isLetter() const { return false; }
304 // is this equivalent to a space (which is BTW different from
305 // a line separator)?
306 virtual bool isSpace() const { return false; }
307 // should we have a non-filled line before this inset?
308 virtual bool display() const { return false; }
309 // should we break lines after this inset?
310 virtual bool isLineSeparator() const { return false; }
312 virtual void write(Buffer const &, std::ostream &) const {}
314 virtual void read(Buffer const &, LyXLex &) {}
315 /// returns the number of rows (\n's) of generated tex code.
316 virtual int latex(Buffer const &, std::ostream &,
317 OutputParams const &) const { return 0; }
318 /// returns true to override begin and end inset in file
319 virtual bool directWrite() const;
321 virtual bool allowSpellCheck() const { return false; }
323 /// if this insets owns text cells (e.g. InsetText) return cell num
324 virtual LyXText * getText(int /*num*/) const { return 0; }
326 virtual int numParagraphs() const { return 0; }
327 /// returns cell covering position (x,y), -1 if none exists
328 virtual int getCell(int x, int y) const;
330 /** Adds a LaTeX snippet to the Preview Loader for transformation
331 * into a bitmap image. Does not start the laoding process.
333 * Most insets have no interest in this capability, so the method
336 virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
338 // the real dispatcher
340 DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
342 /// returns LyX code associated with the inset. Used for TOC, ...)
343 virtual Code lyxCode() const { return NO_CODE; }
345 /// -1: text mode, 1: math mode, 0 undecided
346 enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
347 /// return text or mathmode if that is possible to determine
348 virtual mode_type currentMode() const { return UNDECIDED_MODE; }
350 /// FIXME: This ought to die.
351 virtual void setOwner(UpdatableInset *) {}
353 virtual UpdatableInset * owner() const { return 0; }
355 /// is this inset allowed within a font change?
356 virtual bool noFontChange() const { return false; }
359 virtual void markErased();
361 virtual int width() const { return 10; }
363 virtual int ascent() const { return 10; }
365 virtual int descent() const { return 10; }
370 * returns true if pointer argument is valid
371 * and points to an editable inset
373 bool isEditableInset(InsetBase const * inset);
377 * returns true if pointer argument is valid
378 * and points to a highly editable inset
380 bool isHighlyEditableInset(InsetBase const * inset);