2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2001 the LyX Team.
9 * ====================================================== */
21 #include "commandtags.h"
36 /** This is not quite the correct place for this enum. I think
37 the correct would be to let each subclass of Inset declare
38 its own enum code. Actually the notion of an Inset::Code
39 should be avoided, but I am not sure how this could be done
45 TOC_CODE, // do these insets really need a code? (ale)
91 SPECIALCHAR_CODE, // 25
101 MATHMACRO_CODE, // 30
113 TEXT_TO_INSET_OFFSET = 2
127 Inset() : top_x(0), top_baseline(0), scx(0), owner_(0) {}
128 /// Virtual base destructor
131 virtual int ascent(BufferView *, LyXFont const &) const = 0;
133 virtual int descent(BufferView *, LyXFont const &) const = 0;
135 virtual int width(BufferView *, LyXFont const &) const = 0;
137 virtual void draw(BufferView *, LyXFont const &,
138 int baseline, float & x, bool cleared) const = 0;
139 /// update the inset representation
140 virtual void update(BufferView *, LyXFont const &, bool = false)
143 virtual LyXFont const convertFont(LyXFont const & font) const;
144 /// what appears in the minibuffer when opening
145 virtual string const editMessage() const;
147 virtual void edit(BufferView *, int x, int y, unsigned int button);
149 virtual EDITABLE editable() const;
150 /// This is called when the user clicks inside an inset
151 virtual void insetButtonPress(BufferView *, int, int, int) {}
152 /// This is called when the user releases the button inside an inset
153 virtual void insetButtonRelease(BufferView *, int, int, int) {}
154 /// This is caleld when the user moves the mouse inside an inset
155 virtual void insetMotionNotify(BufferView *, int , int , int) {}
157 virtual bool isTextInset() const { return false; }
159 virtual bool doClearArea() const { return true; }
161 virtual bool autoDelete() const;
163 virtual void write(Buffer const *, std::ostream &) const = 0;
165 virtual void read(Buffer const *, LyXLex & lex) = 0;
166 /** returns the number of rows (\n's) of generated tex code.
167 fragile == true means, that the inset should take care about
168 fragile commands by adding a \protect before.
169 If the free_spc (freespacing) variable is set, then this inset
170 is in a free-spacing paragraph.
172 virtual int latex(Buffer const *, std::ostream &, bool fragile,
173 bool free_spc) const = 0;
175 virtual int ascii(Buffer const *,
176 std::ostream &, int linelen = 0) const = 0;
178 virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
180 virtual int docBook(Buffer const *, std::ostream &) const = 0;
181 /// Updates needed features for this inset.
182 virtual void validate(LaTeXFeatures & features) const;
184 virtual bool deletable() const;
186 /// returns LyX code associated with the inset. Used for TOC, ...)
187 virtual Inset::Code lyxCode() const { return NO_CODE; }
189 virtual std::vector<string> const getLabelList() const {
190 return std::vector<string>();
194 virtual Inset * clone(Buffer const &) const = 0;
196 /// returns true to override begin and end inset in file
197 virtual bool directWrite() const;
199 /// Returns true if the inset should be centered alone
200 virtual bool display() const { return false; }
201 /// Changes the display state of the inset
202 virtual void display(bool) {}
204 /// returns true if this inset needs a row on it's own
206 virtual bool needFullRow() const { return false; }
208 virtual bool insertInsetAllowed(Inset *) const { return false; }
210 void setInsetName(string const & s) { name = s; }
212 string const getInsetName() const { return name; }
214 void setOwner(Inset * inset) { owner_ = inset; }
216 Inset * owner() const { return owner_; }
218 int x() const { return top_x; }
220 int y() const { return top_baseline; }
222 // because we could have fake text insets and have to call this
223 // inside them without cast!!!
225 virtual LyXText * getLyXText(BufferView const *,
226 bool const recursive = false) const;
228 virtual void deleteLyXText(BufferView *, bool = true) const {}
230 virtual void resizeLyXText(BufferView *, bool /*force*/= false) const {}
231 /// returns the actuall scroll-value
232 virtual int scroll(bool recursive=true) const {
233 if (!recursive || !owner_)
242 mutable int top_baseline;
253 // Updatable Insets. These insets can be locked and receive
254 // directly user interaction. Currently used only for mathed.
255 // Note that all pure methods from Inset class are pure here too.
256 // [Alejandro 080596]
258 /** Extracted from Matthias notes:
260 * An inset can simple call LockInset in it's edit call and *ONLY*
263 * Unlocking is either done by LyX or the inset itself with a
266 * During the lock, all button and keyboard events will be modified
267 * and send to the inset through the following inset-features. Note that
268 * Inset::insetUnlock will be called from inside UnlockInset. It is meant
269 * to contain the code for restoring the menus and things like this.
271 * If a inset wishes any redraw and/or update it just has to call
274 * It's is completly irrelevant, where the inset is. UpdateInset will
275 * find it in any paragraph in any buffer.
276 * Of course the_locking_inset and the insets in the current paragraph/buffer
277 * are checked first, so no performance problem should occur.
279 class UpdatableInset : public Inset {
281 /** Dispatch result codes
282 Now that nested updatable insets are allowed, the local dispatch
283 becomes a bit complex, just two possible results (boolean)
286 DISPATCHED = the inset catched the action
287 DISPATCHED_NOUPDATE = the inset catched the action and no update
288 is needed here to redraw the inset
289 FINISHED = the inset must be unlocked as a result
291 UNDISPATCHED = the action was not catched, it should be
292 dispatched by lower level insets
301 /// To convert old binary dispatch results
302 RESULT DISPATCH_RESULT(bool b) {
303 return b ? DISPATCHED : FINISHED;
307 UpdatableInset() : cursor_visible_(false), block_drawing_(false) {}
310 virtual EDITABLE editable() const;
312 /// may call ToggleLockedInsetCursor
313 virtual void toggleInsetCursor(BufferView *);
315 virtual void showInsetCursor(BufferView *, bool show = true);
317 virtual void hideInsetCursor(BufferView *);
319 virtual void getCursorPos(BufferView *, int &, int &) const {}
321 virtual void insetButtonPress(BufferView *, int x, int y, int button);
323 virtual void insetButtonRelease(BufferView *,
324 int x, int y, int button);
326 virtual void insetKeyPress(XKeyEvent * ev);
328 virtual void insetMotionNotify(BufferView *, int x, int y, int state);
330 virtual void insetUnlock(BufferView *);
332 virtual void edit(BufferView *, int x, int y, unsigned int button);
334 virtual void draw(BufferView *, LyXFont const &,
335 int baseline, float & x, bool cleared) const;
337 virtual void setFont(BufferView *, LyXFont const &,
338 bool toggleall = false, bool selectall = false);
340 virtual bool insertInset(BufferView *, Inset *) { return false; }
342 virtual bool insertInsetAllowed(Inset *) const { return true; }
344 virtual UpdatableInset * getLockingInset() { return this; }
346 virtual UpdatableInset * getFirstLockingInsetOfType(Inset::Code c)
347 { return (c == lyxCode()) ? this : 0; }
349 virtual unsigned int insetInInsetY() { return 0; }
351 virtual bool updateInsetInInset(BufferView *, Inset *)
354 virtual bool lockInsetInInset(BufferView *, UpdatableInset *)
357 virtual bool unlockInsetInInset(BufferView *, UpdatableInset *,
360 /// An updatable inset could handle lyx editing commands
361 virtual RESULT localDispatch(BufferView *, kb_action, string const &);
363 bool isCursorVisible() const { return cursor_visible_; }
365 virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
367 int scroll(bool recursive = true) const {
368 // We need this method to not clobber the real method in Inset
369 return Inset::scroll(recursive);
372 virtual bool showInsetDialog(BufferView *) const { return false; }
374 virtual void nodraw(bool b) {
378 virtual bool nodraw() const {
379 return block_drawing_;
384 void toggleCursorVisible() const {
385 cursor_visible_ = !cursor_visible_;
388 void setCursorVisible(bool b) const {
391 /// scrolls to absolute position in bufferview-workwidth * sx units
392 void scroll(BufferView *, float sx) const;
393 /// scrolls offset pixels
394 void scroll(BufferView *, int offset) const;
398 mutable bool cursor_visible_;